0% found this document useful (0 votes)
51 views3 pages

Python Data Analytics Techniques

The document provides examples of using Python for data analytics tasks like handling missing data, subtracting dates, representing dates in different formats, and visualizing and analyzing a dataset on Indian cities.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
51 views3 pages

Python Data Analytics Techniques

The document provides examples of using Python for data analytics tasks like handling missing data, subtracting dates, representing dates in different formats, and visualizing and analyzing a dataset on Indian cities.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

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

import pandas as pd

from [Link] import SimpleImputer

# Load the CSV file into a DataFrame

data = pd.read_csv('D:\[Link]')

# Initialize the SimpleImputer with mean strategy (you can choose other strategies)

imputer = SimpleImputer(strategy='mean')

# Impute missing values in the 'Salaries' column

data['Salaries'] = imputer.fit_transform(data[['Salaries']])

# Filter data where 'Salaries' is less than 70000

filtered_data = data[data['Salaries'] < 70000]

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:

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.

from datetime import date

# Define the start and end dates

start_date = date(2007, 5, 9)

end_date = date(2007, 12, 13)

# Calculate the difference between dates

days_elapsed = (end_date - start_date).days

print(f"Days elapsed between the first and last hurricane in 2007: {days_elapsed} days")

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)'

# Create a date object for August 26, 1992

hurricane_date = date(1992, 8, 26)

# Print the date in different formats

print("Different representations of August 26, 1992:")

from datetime import datetime

# Define the date

Andrew = datetime(1992, 8, 26)


# Print in 'YYYY-MM' format

print([Link]('%Y-%m'))

# Print in 'YYYY-DDD' format

print([Link]('%Y-%j'))

# Print in 'MONTH (YYYY)' format

print([Link]('%B (%Y)'))

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.

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

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.

Common questions

Powered by AI

The process involves sorting the dataset by 'total effective literacy rate' to identify the top-performing cities. Once identified, each city's geographical location (in terms of city name and possibly GPS coordinates) is correlated with its literacy rate, providing a spatial dimension to literacy statistics. This analysis is crucial for understanding regional disparities, facilitating targeted educational interventions, and resource allocation. The geographic context allows policymakers to gauge education success and challenges closely tied to local conditions .

Python's '.strftime()' method formats date objects into various string representations according to specified format codes. For example, the date August 26, 1992, can be represented in 'YYYY-MM' format as '1992-08', in 'YYYY-DDD' format as '1992-239', and in 'MONTH (YYYY)' format as 'August (1992)'. These formats serve different purposes, such as providing clear, language-agnostic dates or easily integrating dates into text narratives. This flexibility allows users to select the appropriate level of detail and readability based on context .

Python's 'sklearn.impute' module can handle missing data using the 'SimpleImputer' class. This class replaces missing values in a specified column with the mean (or other possible strategies) of the available data. After handling the missing values, data can be filtered using criteria such as a threshold for a numerical column; for instance, filtering records where 'Salaries' are less than 70,000. The relevant code would load a CSV into a pandas DataFrame, apply 'SimpleImputer' to impute missing 'Salaries', and filter accordingly to obtain the desired subset of data .

Dealing with null values typically involves options such as deletion, imputation, or replacement. Deletion removes rows with any null value, suitable when missing data is limited to avoid biased results. Imputation fills in missing values with meaningful substitutes, often using statistical methods like mean or median for numerical data. It is vital to address null values to prevent analytical inaccuracies caused by incomplete data, ensuring reliability and validity of insights drawn from dataset analyses .

Plotting a scatter plot between 'male graduates' and 'female graduates' helps visualize the relationship and potential correlation in graduate distribution across Indian cities. It can reveal trends, such as whether cities show balanced gender education levels or have discrepancies indicating gender-based educational inequality. Patterns, clusters, or deviations captured visually can direct focus to areas needing gender-specific educational policies or reforms. This plot effectively reveals data interactions that mere tabulation might miss .

Using Python to represent dates in varied formats improves clarity and comprehension, catering to different communication needs. For example, 'YYYY-MM' is compact and international, 'YYYY-DDD' provides cumulative day count information, and 'MONTH (YYYY)' offers a reader-friendly format for narratives. This flexibility aids in aligning the date presentation with specific context requirements, such as technical documentation, data analysis, or casual communication, enhancing the effectiveness and professionalism of data reporting .

Filtering salaries under a specific threshold, such as 70,000, focuses the analysis on a subset of data that may reveal insights about low-income groups or sectors. This targeted approach helps stakeholders understand income distribution patterns, identify socio-economic challenges, and direct interventions more efficiently. It provides more relevant insights for financial assessments, policy formulation, or market analysis, leading to data-driven decisions tailored to address specific issues like poverty alleviation or wage growth strategies .

Python provides date arithmetic operations through the 'datetime' module, where date objects allow subtraction to yield a timedelta object representing the difference in days between two dates. By creating date objects for specific dates (using 'datetime.date'), the subtraction operation is straightforward. For example, subtracting a start date (May 9, 2007) from an end date (December 13, 2007) gives the number of days elapsed between them, calculated as 218 days .

Boxplots provide a visual summary of 'total effective literacy rate' by displaying the central tendency, variability, and potential outliers in the data. It displays median, quartiles, and extreme values, offering insights into data distribution and identifying skewness or anomalies. Analyzing the interquartile range (IQR) can indicate the consistency of literacy rates across cities. Boxplots uncover outliers, prompting further investigation. They help in quickly assessing the overall data spread and spotting cities that diverge from the trend, guiding targeted literacy interventions .

Constructing a histogram of the 'literates_total' attribute in a dataset provides insights into the distribution of literacy among cities. It can reveal patterns such as skewness, peaks, or gaps, indicating how literacy levels vary across different cities. Such visualization helps in identifying clusters or anomalies in the data, guiding further analysis or resource allocation. It offers a visual summary of data distribution, aiding in pattern recognition and strategic decision-making .

You might also like