Python For Data Analytics
Python For Data Analytics
1) Please take care of missing data present in the “Data.csv” file using python module
“sklearn.impute” and its methods, also collect all the data that has “Salary” less than
“70,000”.
import pandas as pd
data = pd.read_csv('D:\Data.csv')
# Initialize the SimpleImputer with mean strategy (you can choose other strategies)
imputer = SimpleImputer(strategy='mean')
data['Salaries'] = imputer.fit_transform(data[['Salaries']])
print(filtered_data)
2) Subtracting dates:
Python date objects let us treat calendar dates as something similar to numbers: we can
compare them, sort them, add, and even subtract them. Do math with dates in a way that
would be a pain to do by hand. The 2007 Florida hurricane season was one of the busiest
on record, with 8 hurricanes in one year. The first one hit on May 9th, 2007, and the last
one hit on December 13th, 2007. How many days elapsed between the first and last
hurricane in 2007?
Instructions:
Create a date object for May 9th, 2007, and assign it to the start variable.
Create a date object for December 13th, 2007, and assign it to the end variable.
Subtract start from end, to print the number of days in the resulting timedelta
object.
start_date = date(2007, 5, 9)
print(f"Days elapsed between the first and last hurricane in 2007: {days_elapsed} days")
Date objects in Python have a great number of ways they can be printed out as strings. In
some cases, you want to know the date in a clear, language-agnostic format. In other
cases, you want something which can fit into a paragraph and flow naturally.
Print out the same date, August 26, 1992 (the day that Hurricane Andrew made landfall in
Florida), in a number of different ways, by using the “ .strftime() ” method. Store it in a
variable called “Andrew”.
Instructions:
print(Andrew.strftime('%Y-%m'))
print(Andrew.strftime('%Y-%j'))
print(Andrew.strftime('%B (%Y)'))