Practical 1 and 2-1
Practical 1 and 2-1
OUTPUT:
01/02/2024
OUTPUT:
21/02/2024
OUTPUT:
21/02/2024
OUTPUT:
21/02/2024
OUTPUT:
28/02/2024
OUTPUT:
28/02/2024
print("Series:")
print(series)
print("\nMinimum ranks (using 'first' method):")
print(min_ranks_first)
print("\nMaximum ranks (using 'max' method):")
print(max_ranks_max)
OUTPUT:
28/02/2024
OUTPUT:
06/03/2024
OUTPUT:
06/03/2024
OUTPUT:
06/03/2024
OUTPUT:
06/03/2024
OUTPUT:
06/03/2024
OUTPUT:
06/03/2024
OUTPUT:
06/03/2024
OUTPUT:
13/03/2024
Practical → 6th
Q Consider the following data frame containing a family name, gender of the family
member and her/his monthly income in each record.
CODE:
import pandas as pd
df = pd.DataFrame(data)
print(df)
OUTPUT:
13/03/2024
OUTPUT:
21/03/2024
CODE:
import pandas as pd
titanic_df = pd.read_csv("C:/Users/DELL/Downloads/titanic.csv")
# a. Total number of passengers with age less than 30
passengers_under_30 = titanic_df[titanic_df['Age'] < 30]
total_passengers_under_30 = passengers_under_30.shape[0]
print("Total number of passengers with age less than 30:",
total_passengers_under_30)
OUTPUT:
21/03/2024
CODE:
import pandas as pd
titanic_df = pd.read_csv("C:/Users/DELL/Downloads/titanic.csv")
# b. Total fare paid by passengers of first class
first_class_fare = titanic_df[titanic_df['Pclass'] == 1]['Fare'].sum()
print("Total fare paid by passengers of first class:", first_class_fare)
OUTPUT:
21/03/2024
CODE:
import pandas as pd
titanic_df = pd.read_csv("C:/Users/DELL/Downloads/titanic.csv")
# c. Number of survivors of each passenger class
survivors_by_class = titanic_df.groupby('Pclass')['Survived'].sum()
print("Number of survivors of each passenger class:")
print(survivors_by_class)
OUTPUT:
21/03/2024
CODE:
import pandas as pd
titanic_df = pd.read_csv("C:/Users/DELL/Downloads/titanic.csv")
# d. Descriptive statistics for age attribute genderwise
descriptive_stats_genderwise = titanic_df.groupby('Sex')['Age'].describe()
print("Descriptive statistics for age attribute genderwise:")
print(descriptive_stats_genderwise)
OUTPUT:
17/04/2024
Practical → 4th
Q4. Consider two Excel files having an attendance of two workshops. Each file has three
fields ‘Name’, ‘Date, duration (in minutes) where names are unique within a file. Note
that duration may take one of three values (30, 40, 50) only. Import the data into two
data frames.
CODE:
import pandas as pd
# Display the first few rows of each data frame to verify the data
print("Data Frame 1:")
print(df1)
OUTPUT:
Q. Import the data into two data frames and do the following:
a. Perform a merging of the two data frames to find the names of students
who had attended both workshops.
b. Find the names of all students who have attended a single workshop only.
c. Merge two data frames row-wise and find the total number of records in
the data frame.
d. Merge two data frames row-wise and use two columns viz. names and
dates as multi-row indexes. Generate descriptive statistics for this
hierarchical data frame.
CODE:
# a. Perform merging of the two data frames to find the names of students who had attended
both workshops.
attended_both = pd.merge(df1, df2, how='inner', on='Name')
print("\nNames of students who attended both workshops:")
print(attended_both['Name'].unique())
# b. Find names of all students who have attended a single workshop only.
attended_either = pd.merge(df1, df2, how='outer', on='Name', indicator=True)
attended_single = attended_either[attended_either['_merge'].isin(['left_only', 'right_only'])]
print("\nNames of students who attended a single workshop only:")
print(attended_single['Name'].unique())
# c. Merge two data frames row-wise and find the total number of records in the data frame.
merged_df = pd.concat([df1, df2], ignore_index=True)
print("\nTotal number of records in the merged data frame:", len(merged_df))
# d. Merge two data frames row-wise and use two columns viz. names and dates as multi-row
indexes.
# Generate descriptive statistics for this hierarchical data frame.
merged_df_multi_index = pd.concat([df1.set_index(['Name', 'Date']), df2.set_index(['Name',
'Date'])], axis=0)
print("\nDescriptive statistics for the hierarchical data frame:")
print(merged_df_multi_index.describe())
OUTPUT:
24/04/2024
OUTPUT:
24/04/2024
OUTPUT:
24/04/2024
OUTPUT:
24/04/2024
OUTPUT:
24/04/2024
OUTPUT:
24/04/2024
OUTPUT:
24/04/2024