CBSE Class 12 Informatics Practices
Question 38 of 44
Data Handling using Pandas — Question 39
Back to all questions 39
Question Create a dataframe of D1 and D2;
D1 = {‘Rollno’ : [1001, 1004, 1005, 1008, 1009], ‘Name’: [‘Sarika’, ‘Abhay’, ‘Mohit’, ‘Ruby’, ‘Govind’ ]}
D2 = {‘Rollno’ : [1002, 1003, 1004, 1005, 1006], ‘Name’:[‘Seema’,‘Jia’,‘Shweta’, ‘Sonia’, ‘Nishant’]}
(a) Concatenate row-wise.
(b) Concatenate column-wise.
The DataFrame D1 and D2 are created as :
import pandas as pd
Data1 = {'Rollno': [1001, 1004, 1005, 1008, 1009], 'Name': ['Sarika', 'Abhay', 'Mahit', 'Ruby', 'Govind']}
Data2 = {'Rollno': [1002, 1003, 1004, 1005, 1006], 'Name': ['Seema', 'Jia', 'Shweta', 'Sonia', 'Nishant']}
D1 = pd.DataFrame(Data1)
D2 = pd.DataFrame(Data2)
print(D1)
print(D2) Rollno Name
0 1001 Sarika
1 1004 Abhay
2 1005 Mahit
3 1008 Ruby
4 1009 Govind
Rollno Name
0 1002 Seema
1 1003 Jia
2 1004 Shweta
3 1005 Sonia
4 1006 Nishant
(a)
df = pd.concat([D1, D2]) Rollno Name
0 1001 Sarika
1 1004 Abhay
2 1005 Mahit
3 1008 Ruby
4 1009 Govind
0 1002 Seema
1 1003 Jia
2 1004 Shweta
3 1005 Sonia
4 1006 Nishant
(b)
df = pd.concat([D1, D2], axis=1) Rollno Name Rollno Name
0 1001 Sarika 1002 Seema
1 1004 Abhay 1003 Jia
2 1005 Mahit 1004 Shweta
3 1008 Ruby 1005 Sonia
4 1009 Govind 1006 Nishant