0% found this document useful (0 votes)
18 views11 pages

Python Analytics for Data Insights

The document outlines an assignment for Python coding focused on data analytics, including tasks such as handling missing data, date calculations, and data visualization using datasets like 'Data.csv' and 'Indian_cities'. Specific tasks involve using sklearn for imputation, calculating days between dates, formatting dates, and generating various plots and analyses related to sex ratios and literacy rates. The assignment emphasizes practical implementation of Python for data manipulation and analysis.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
18 views11 pages

Python Analytics for Data Insights

The document outlines an assignment for Python coding focused on data analytics, including tasks such as handling missing data, date calculations, and data visualization using datasets like 'Data.csv' and 'Indian_cities'. Specific tasks involve using sklearn for imputation, calculating days between dates, formatting dates, and generating various plots and analyses related to sex ratios and literacy rates. The assignment emphasizes practical implementation of Python for data manipulation and analysis.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

MODULE – 7 ASSIGNMENT

Python for data analytics

Please implement Python coding for all the problems.

1)​ Please take care of missing data present in the “[Link]” file using python module
“[Link]” and its methods, also collect all the data that has “Salary” less than
“70,000”.

© 360DigiTMG. All Rights Reserved.


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:

​ Import date from datetime.

​ 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.

© 360DigiTMG. All Rights Reserved.


3) Representing dates in different ways

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 it in the format 'YYYY-MM', 'YYYY-DDD' and 'MONTH (YYYY)'

© 360DigiTMG. All Rights Reserved.


4) For the dataset “Indian_cities”,
a)​ Find out top 10 states in female-male sex ratio
b)​ Find out top 10 cities in total number of graduates
c)​ Find out top 10 cities and their locations in respect of total effective_literacy_rate.

© 360DigiTMG. All Rights Reserved.


© 360DigiTMG. All Rights Reserved.
5) For the data set “Indian_cities”
a)​ Construct histogram on literates_total and comment about the inferences
b)​ Construct scatter plot between male graduates and female graduates

© 360DigiTMG. All Rights Reserved.


© 360DigiTMG. All Rights Reserved.
© 360DigiTMG. All Rights Reserved.
© 360DigiTMG. All Rights Reserved.
6) For the data set “Indian_cities”
a)​ Construct Boxplot on total effective literacy rate and draw inferences
b)​ Find out the number of null values in each column of the dataset and delete them.

© 360DigiTMG. All Rights Reserved.


© 360DigiTMG. All Rights Reserved.

Common questions

Powered by AI

To identify the top 10 states by female-male sex ratio using city-level data, first, aggregate the data at the state level, focusing on aggregating female and male populations. Subsequently, compute the sex ratio for each state, possibly using pandas for data manipulation. Sort the states by their computed sex ratio in descending order and select the top 10 states. This approach ensures accurate representation and allows for comparison among states based on city averages.

To calculate the number of days between two dates in Python, import the datetime module, create date objects for the specified dates, and then subtract one date object from the other. This subtraction yields a timedelta object from which you can access the 'days' attribute. For example, define the start date as May 9, 2007, and the end date as December 13, 2007, and calculate the difference using timedelta = end - start, where timedelta.days will give you the exact number of days elapsed, which is 218 days.

Analyzing the top 10 cities in graduate numbers may face challenges like data completeness, varying definitions of 'graduate', and differing city sizes. Incomplete data can skew rankings, while inconsistent graduate definitions across surveys might yield misleading comparisons. Another issue is not accounting for varied population sizes which could exaggerate differences. Address these challenges by ensuring data completeness, standardizing terms, perhaps normalizing graduates per capita, and using visualizations to contextualize the data, thus ensuring robust analysis.

Utilizing various date representations in data analytics enhances flexibility and clarity. Clear formats like 'YYYY-MM-DD' are beneficial for analysis and comparison, while more narrative formats such as 'Month (YYYY)' aid in communicating findings in reports. For events like hurricanes, precise date formats can help in time series analysis and pattern detection, while natural language formats improve readability in narratives. Thus, date formatting serves both technical and communicative functions in data analytics.

To find and efficiently remove null values from a dataset, use pandas to first identify columns with null values using the .isnull().sum() method, which provides the count of nulls per column. Once identified, decide whether to drop or impute those values based on their significance and proportion. The .dropna() method is effective for removing rows or columns with nulls, ensuring that data integrity and analysis accuracy are upheld without undue loss of information.

To construct a boxplot of the total effective literacy rate, use a data visualization library like matplotlib or seaborn. A boxplot visualizes the distribution of literacy rates, displaying the median, quartiles, and potential outliers. The box represents the interquartile range (IQR), with the line inside showing the median literacy rate. Analysis might reveal asymmetry (skewness), variation (spread of IQR), and outliers, which are cities deviating significantly from others in terms of literacy rate. Such insights can guide resource allocation and policy formulation.

A scatter plot between male and female graduates in Indian cities can reveal correlations and disparities in educational attainment between genders. The shape of the scatter plot, linearity, outliers, and clustering of points can indicate whether male and female graduate numbers increase in tandem or if there are significant discrepancies. A highly positive correlation would suggest parity in educational access, while deviations might highlight gender-specific barriers. Identifying clusters or outliers can direct attention to cities requiring targeted educational policies.

To manage missing data using Python's sklearn.impute module, you can use the SimpleImputer class which allows for imputation of missing values using strategies such as mean, median, or most frequent. For handling missing salary data from a CSV file, you first import the dataset using pandas, then apply SimpleImputer to fill missing values. For instance, from sklearn.impute import SimpleImputer, create an instance specifying the strategy, and fit it to the column of interest. Finally, transform the column to replace missing values. This helps maintain the integrity of the dataset without reducing its size unnecessarily by dropping missing records.

Constructing a histogram for total literates in Indian cities allows identification of distribution trends such as skewness, central tendency, and variability. For instance, if the histogram shows a right-skewed distribution, it indicates that while most cities have a moderate number of literates, a few cities have an exceptionally high number, suggesting disparity in literacy levels. Furthermore, peaks (modes) might reveal clustering of data points around certain literacy levels, and insights into population density and urban-rural divide in literacy can also be inferred.

Python's .strftime() method allows for flexible date formatting. For the landfall date of Hurricane Andrew, August 26, 1992, you can represent it in various formats: 'YYYY-MM' as '1992-08', 'YYYY-DDD' as '1992-239' (where 239 is the day of the year), and 'MONTH (YYYY)' as 'August (1992)'. This method helps in converting the date into a string format suitable for different contexts and use cases.

You might also like