Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

EXPERIMENT-4

15.04.2024
AIM: Consider two excel files having attendance of two workshops. Each file has three
fields: ‘Name’, ‘Date’ and ‘Duration(min) where names are unique within the file.
Duration may take one of three values (30,40,50) only. Import the data into two data
frames and do the following:
a. Perform merging the two data frames to find the names of students who had
attended both workshops.
b. Find names of all students who have attended a single workshop only.
c. Merge two data frames row-wise and find total number of records in the data
frame.
d. Merge data frames row-wise and use two columns viz. names and dates as multi-
row indexes. Generate descriptive statistics for the hierarchical data frame.
CODE:
import pandas as pd
df1=pd.read_excel('Workshop1.xlsx')
df2=pd.read_excel('Workshop2.xlsx')
both_attended=pd.merge(df1,df2,on='Name',how='inner')['Name']
single_attended=pd.concat([df1[~df1['Name'].isin(df2['Name'])]['Name'],df2[~df2['Na
me'].isin(df1['Name'])]['Name']])
merged_row_wise=pd.concat([df1, df2])
merged_row_wise_multi_index=pd.concat([df1.set_index(['Name',
'Date']),df2.set_index(['Name', 'Date'])])
descriptive_stats=merged_row_wise_multi_index.describe()
print('Students who attended both workshops:',both_attended)
print('\nStudents who attended a single workshop only:',single_attended)
print('\nTotal number of records in the merged data frame (row-wise):',
len(merged_row_wise))
print('\nDescriptive statistics for the hierarchical data frame:',descriptive_stats)
OUTPUT:

You might also like