Document 1
Document 1
PROGRAM1
Aim: Create a pandas series from a dictionary of values and a ndarray.
CODE:
import pandas as pd
import numpy as np
series_from_dict = pd.Series(data_dict)
series_from_ndarray = pd.Series(data_ndarray)
OUTPUT:
PROGRAM2
Aim: Create a Series and print all the elements that are above 75 percentile.
CODE:
# Creating a pandas series
OUTPUT:
PROGRAM3
Aim: Perform sorting on Series data and DataFrames.
CODE:
# Sorting a Series
sorted_series = data_series.sort_values()
# Creating a DataFrame
df = pd.DataFrame({
sorted_df = df.sort_values(by='A')
OUTPUT:
PROGRAM4
Aim: Write a program to implement pivot() and pivot_table() on a DataFrame.
CODE:
data = {
df = pd.DataFrame(data)
# Using pivot
# Using pivot_table
OUTPUT:
PROGRAM5
Aim: Write a program to find mean absolute deviation on a DataFrame.
CODE:
# Creating a DataFrame
df_mad = pd.DataFrame({
'C': [9, 8, 7, 6, 5]
})
mad = df_mad.mad()
OUTPUT:
PROGRAM6
Aim: Two Series objects, Population stores the details of four metro cities of India and
another object AvgIncome stores the total average income reported in four years in these
cities. Calculate income per capita for each of these metro cities.
CODE:
OUTPUT:
PROGRAM7
Aim: Create a DataFrame based on E-Commerce data and generate mean, mode, median.
CODE:
# Creating a DataFrame
ecommerce_data = pd.DataFrame({
})
mean_price = ecommerce_data['Price'].mean()
mode_price = ecommerce_data['Price'].mode()[0]
median_price = ecommerce_data['Price'].median()
OUTPUT:
PROGRAM8
Aim: Create a DataFrame based on employee data and generate quartile and variance.
CODE:
# Creating a DataFrame
employee_data = pd.DataFrame({
})
variance = employee_data.var()
print("\nQuartiles:\n", quartiles)
print("\nVariance:\n", variance)
OUTPUT:
PROGRAM9
Aim: Program to implement skewness on random data.
CODE:
random_data = np.random.randn(1000)
# Calculating skewness
skewness = pd.Series(random_data).skew()
OUTPUT:
PROGRAM10
Aim: Create a DataFrame on any data and compute statistical function of kurtosis.
CODE:
# Creating a DataFrame
data_kurtosis = pd.DataFrame({
'Data': np.random.randn(1000)
})
# Calculating kurtosis
kurtosis = data_kurtosis.kurtosis()
print("\nKurtosis:\n", kurtosis)
OUTPUT:
PROGRAM11
Aim: Series objects Temp1, temp2, temp3, temp4 store the temperature of days of week 1,
week 2, week 3, week 4. Write a script to: -
a. prints the average temperature per week.
b. Print average temperature of entire month.
CODE:
# Calculating average temperature per week and for the entire month
avg_per_week = temps.mean()
avg_entire_month = temps.stack().mean()
OUTPUT:
PROGRAM12
Aim: Write a Program to read a CSV file and create its DataFrame.
CODE:
# df_csv = pd.read_csv('path_to_your_csv_file.csv')
df_csv = pd.DataFrame({
})
OUTPUT:
PROGRAM13
Aim: Consider the DataFrame QtrSales where each row contains the item category, item
name, and expenditure and group the rows by category. Print the average expenditure per
category.
CODE:
grouped = df_csv.groupby('Category')['Expenditure'].mean()
OUTPUT:
PROGRAM14
Aim: Create a DataFrame having age, name, weight of five students. Write a program to
display only the weight of first and fourth rows.
CODE:
# Creating a DataFrame
students_data = pd.DataFrame({
})
OUTPUT:
PROGRAM15
Aim: Write a program to create a DataFrame to store weight, age, and name of three people.
Print the DataFrame and its transpose.
CODE:
# Creating a DataFrame
people_data = pd.DataFrame({
})
OUTPUT: