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

In [4]: import pandas as pd

# Read the two Excel files into data frames


df1 = pd.read_excel('workshop1.xlsx')
df2 = pd.read_excel('workshop2.xlsx')

# 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)

Names of students who attended both workshops: 0 khushi


1 prachi
2 gupta
3 verma
4 diwakar
5 keshav
6 aaryan
7 rana
Name: name, dtype: object

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)

Total number of records in the merged data frame: 36

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)

Descriptive statistics for the hierarchical data frame:


duration
count 36.000000
mean 38.888889
std 8.873002
min 20.000000
25% 30.000000
50% 40.000000
75% 50.000000
max 50.000000

In [10]: print('By- Aaryan Pandey 13591')

By- Aaryan Pandey 13591

In [ ]:

You might also like