Ids 1
Ids 1
TECHNOLOGY
PRACTICAL FILE
OF
BCA 212P
(INTRODUCTION OF DATA SCIENCE)
Academic session: 2024-25
Batch: 2023-26
2
Experiment -1
Create a pandas series from a dictionary of values and an
ndarray.
Code: -
import pandas as pd
import numpy as np
data=np.array([1,2,3,4,5])
Series1=pd.Series(data)
print(Series1)
data_dict={"a":10,"b":20,"c":30}
Series2=pd.Series(data_dict)
print(Series2)
Output: -
3
Experiment-2
Create a Series and print all the elements that are above 75th
percentile.
Code: -
import pandas as pd
import numpy as np
print("Original Series:\n", s)
percentile_75 = s.quantile(0.75)
Output: -
4
Experiment-3
Perform sorting on Series data and DataFrames.
Code: -
import pandas as pd
# Create a Series
sorted_series = my_series.sort_values()
sorted_series_desc = my_series.sort_values(ascending=False)
# Create a DataFrame
my_df = pd.DataFrame(data)
sorted_df = my_df.sort_values(by='Age')
5
# Sort the DataFrame by 'Name' (alphabetical order)
sorted_df_name = my_df.sort_values(by='Name')
Output: -
6
7
Experiment-4
Write a program to implement pivot() and pivot-table() on a
DataFrame.
Code: -
import pandas as pd
# Sample DataFrame
data = {
'Date': ['2023-01-01', '2023-01-01', '2023-01-02', '2023-01-02', '2023-01-03'],
'Category': ['A', 'B', 'A', 'B', 'A'],
'Value': [10, 20, 15, 25, 30]
}
df = pd.DataFrame(data)
8
print("\nPivoted DataFrame using pivot_table():")
print(pivot_table_df)
Output: -
9
Experiment-5
Write a program to find mean absolute deviation on a
DataFrame.
Code: -
import pandas as pd
# Sample DataFrame
data = {
'A': [1, 2, 3, 4, 5],
'B': [5, 6, 7, 8, 9],
'C': [10, 11, 12, 13, 14]
}
df = pd.DataFrame(data)
print("Original DataFrame:\n", df)
10
# Display the result
print("Mean Absolute Deviation for each column:")
print(mad_result)
Output: -
11
Experiment-6
Two Series object, 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:-
import pandas as pd
Output:-
13
Experiment-7
Create a DataFrame based on E-Commerce data and generate
mean, mode, median.
Code:-
import pandas as pd
# Create DataFrame
ecommerce_df = pd.DataFrame(data)
# Calculate mean
mean_price = ecommerce_df['Price'].mean()
14
# Calculate mode
mode_price = ecommerce_df['Price'].mode()[0]
# Calculate median
median_price = ecommerce_df['Price'].median()
Output:-
15
Experiment-8
Create a DataFrame based on employee data and generate
quartile and variance.
Code:-
import pandas as pd
# Sample employee data
data = {
'EmployeeID': [1, 2, 3, 4, 5, 6, 7, 8, 9, 10],
'Name': ['Krishna', 'Murali', 'Chaitanya', 'Shyam', 'Govind',
'Madhav', 'Gopal', 'Gopal', 'Murari', 'Keshava'],
'Age': [25, 30, 35, 40, 28, 32, 45, 50, 29, 38],
'Salary': [50000, 60000, 70000, 80000, 55000,
62000, 75000, 90000, 58000, 72000],
'YearsAtCompany': [1, 2, 3, 4, 1, 2, 5, 6, 2, 3]
}
# Create DataFrame
employee_df = pd.DataFrame(data)
# Display the DataFrame
print("Employees Data:")
print(employee_df)
# Calculate quartiles
quartiles_salary = employee_df['Salary'].quantile([0.25, 0.5, 0.75])
quartiles_years = employee_df['YearsAtCompany'].quantile([0.25, 0.5, 0.75])
# Calculate variance
16
variance_salary = employee_df['Salary'].var()
variance_years = employee_df['YearsAtCompany'].var()
# Display the results
print("\nQuartiles for Salary:")
print(quartiles_salary)
print("\nQuartiles for Years at Company:")
print(quartiles_years)
print(f"\nVariance for Salary: {variance_salary}")
print(f"Variance for Years at Company: {variance_years}")
Output: -
17
Experiment-9
Program to implement Skewness on Random data.
Code: -
# Program to implement Skewness on Random data.
import numpy as np
from scipy.stats import skew
# Generate random data
data = data = np.random.normal(1, 100, 15)
print("Random Numbers:")
print(data)
# Calculate skewness
data_skewness = skew(data)
# Print the skewness
print(f"\nSkewness of the data: {data_skewness}")
Output: -
18
Experiment-10
Create a DateFrame on any Data and compute statistical
function of Kurtosis.
Code: -
import pandas as pd
from scipy.stats import kurtosis
# Create DataFrame
employee_df = pd.DataFrame(data)
19
# Display the kurtosis result
print(f"\nKurtosis of Salary: {kurtosis_salary}")
Output: -
20
Experiment-11
Series objects Temp1, temp2, temp3, temp 4 stores the
temperature of days of week 1, week 2, week 3, week 4.
Write a script to:-
a. Print average temperature per week
b. Print average temperature of entire month
Code: -
import pandas as pd
# Create DataFrame
temperature_df = pd.DataFrame(data)
21
print(avg_temp_per_week)
Output: -
22
Experiment-12
Write a Program to read a CSV file and create its DataFrame.
Code: -
CSV File
EmployeeID,Name,Age,Salary
1,Shyam,30,50000
2,Gopal,25,60000
3,Madhav,35,70000
4,keshava,40,80000
5,Murari,28,55000
Python File
import pandas as pd
23
Output: -
24
Experiment-13
Consider the DataFrame QtrSales where each row contains
the item category, item name and expenditure and group the
rows by category, and print the average expenditure per
category.
Code: -
import pandas as pd
# Create DataFrame
QtrSales = pd.DataFrame(data)
25
# Display the average expenditure per category
print("\nAverage Expenditure per Category:")
print(average_expenditure)
Output: -
26
Experiment-14
Create a DataFrame having age, name, weight of five
students. Write a program to display only the weight of first
and fourth rows.
Code: -
import pandas as pd
# Create DataFrame
students_df = pd.DataFrame(data)
28
Experiment-15
Write a program to create a DataFrame to store weight, age
and name of three people. Print the DataFrame and its
transpose.
Code: -
import pandas as pd
# Create DataFrame
people_df = pd.DataFrame(data)
29
Output: -
30