Learn Data Analysis with Python
The image was created using AI.
Hey everyone,
It’s been a while since my last newsletter, and I want to thank all 192 of you for sticking around! I’ve decided to resume this newsletter with a fresh goal — completing a 100-day Data Analysis with Python challenge. The aim is to gain proficiency in solving Python data analysis problems and build a strong project portfolio by the end of it.
This is for anyone who is starting for the first time. Few details are missed intendedly so that you can do some homework!
Let me take you along for this journey, starting from Day 1!
Starting 100-days of learning Data Analysis with Python challenge
Day 1: Basic Python Practice
Tasks Completed:
import sys
print(sys.version)
Here’s a snippet of the code I worked on:
def odd_even(number):
if(number%2 == 0):
print('Number is even')
else:
print('Number is odd')
#using 'ternary operator'(single-line conditional expression), we can write above #code in a single line
# print('Number is even' if number % 2 == 0 else 'Number is odd')
while True:
inp_num = int(input("Enter a number")) #input returns a string by default, that is why it was converted to int.
odd_even(inp_num)
continue_testing = input("Do you want to test another number?(yes/no): ").lower()
if continue_testing not in ['yes', 'no']:
print('Please enter a valid input with yes or no only')
elif (continue_testing != 'yes'):
print("Exiting the program")
break;
# while True: use strip() to handle accidental spaces.
# inp_num = int(input("Enter a number: ")) # Input converted to integer
# odd_even(inp_num)
# continue_testing = input("Test another number? (yes/no): ").strip().lower()
# if continue_testing == 'no':
# print("Exiting the program.")
# break
# elif continue_testing != 'yes':
# print("Invalid input. Please enter 'yes' or 'no'.")
The second suggestion for while loop was given by chatGPT. Let me know what do you think about the second version?
2nd Task:
Square of numbers
for i in range(1,11):
print(f""" The square of {i} is {i**2}""")
An f-string (formatted string literal) is a way to embed expressions inside string literals by prefixing the string with f or F. You can include variables or expressions inside curly braces {} within the string, and Python will evaluate and replace them with their values.
Day 2: Basic File Read/Write Operations
!touch sample.txt
Create a sample file named sample.txt
Add some sample content in the file.
with open('sample.txt', "r") as opened_file: #opening the file in read(r) mode.
#print(opened_file.read()) #read all contents at once
#print(opened_file.readline()) #read line by line
# using a simple `for` loop.
for x in opened_file: #loop through the file
print(x)
Once you're okay with performing this, go to W3 schools and check the basic file read/write operations.
Day 3: Data structures and libraries
fruits = ['Apple', 'Orange', 'Kiwi', 'Banana', 'Avocado'] #list
fruits
fruit_dict = { #dictionary
'Apple': "Red",
'Orange' : 'Saffron',
'Kiwi' : 'Green',
'Banana' : 'Yellow',
'Avocado' : 'Dark Green'
}
print(fruit_dict)
To install numpy use pip or conda.
pip install numpy
import numpy as np
random_numbers = np.random.rand(5) #create an array of 5 random numbers.
print(f""" Random_numbers: {random_numbers}""")
print(f""" Mean of numbers is: {np.mean(random_numbers)} """)
print(f""" Std. deviation of numbers is: {np.std(random_numbers)} """)
Mean is the average of numbers. Std.deviation means how dispersed the data is in relation to the mean.
sample_data = {
'Name': ['Deepak', 'Onika', 'Varnika'],
'Age' : [30, 32, 5],
'Occupation': ['Content Creator', 'Senior Manager | ITSM', 'Pre-nursery student']
}
for name, age, occupation in zip(sample_data['Name'], sample_data['Age'], sample_data['Occupation']):
print(name, age, occupation)
zip() function is considered best practice for iterating over multiple lists together, as it clearly communicates the intent of pairing corresponding elements.
If you want to print just one person's details say Onika, you can do it using below code:
print(f"Name: {sample_data['Name'][1]}, Age: {sample_data['Age'][1]}, Occupation: {sample_data['Occupation'][1]}")
Here, We're referring to the 2nd element in the list which is index 1 as index in a list starts from 0.
One you're comfortable with above tasks, go ahead with Day-4 tasks.
This is your homework. We will discuss about these next week.
Day 4 Tasks
Handling Missing Data:
Sorting Data:
Basic Mathematical Operations with Pandas:
Data Filtering and Subsetting:
Don't forget to install pandas before executing these steps.
So, If you have completed these, here's a screenshot for you covering some of these.
Day 5: Data Visualization(Basic)
Tasks
Data Visualization (Basic):
Group By Operations:
Data Merging:
Applying Functions:
Here are a few code snippets from these tasks. I've decided not to share all of them as you will not exercise by yourself if I do. But I will be happy to answer any questions to address your doubts.
For now, let's see few code examples.
Day 6 Tasks:
Day 7 Tasks:
Day 8 Tasks:
Here is the Homework for you guys.
Let's keep learning and if you've got any suggestions for me to work on, let me know in the comments. :)