Professional Documents
Culture Documents
Prac4.Ipynb (Auto-R) - JupyterLab
Prac4.Ipynb (Auto-R) - JupyterLab
# Task a: Perform merging of the two data frames to find the names of students who attended
both_attended = pd.merge(df1, df2, on='name', how='inner')['name']
print("Names of students who attended both workshops:", both_attended)
In [5]: # Task b: Find names of all students who have attended a single workshop only
single_attended_df1 = df1[~df1['name'].isin(df2['name'])]['name']
single_attended_df2 = df2[~df2['name'].isin(df1['name'])]['name']
single_attended = pd.concat([single_attended_df1, single_attended_df2])
print("\nNames of students who attended a single workshop only:", single_attended.unique())
Names of students who attended a single workshop only: ['abc' 'dfg' 'ttyr' 'yht' 'tyrf' 'yiu'
'erw' 'tryu' 'eryh' 'gj' 'aryan'
'mondal' 'shivam' 'sumit' 'singh' 'srijal' 'kumar' 'soni' 'ayush'
'bhavya']
In [6]: # Task c: Merge two data frames row-wise and find the total number of records in the data fr
merged_row_wise = pd.concat([df1, df2])
total_records = len(merged_row_wise)
print("\nTotal number of records in the merged data frame:", total_records)
In [9]: # Task d: Merge two data frames row-wise and use two columns viz. names and dates as multi-r
# Generate descriptive statistics for this hierarchical data frame
merged_hierarchical = pd.concat([df1.set_index(['name', 'date']), df2.set_index(['name', 'da
descriptive_stats = merged_hierarchical.describe()
print("\nDescriptive statistics for the hierarchical data frame:")
print(descriptive_stats)
In [ ]: