Informatics Practices
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.
Answer
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)
Output
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])
Output
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)
Output
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
Related Questions
Create a dataframe using list [10, 11, 12, 13, 14] [23, 34, 45, 32, 65] [55, 60, 65, 70, 75] and do the following:
(a) Display the dataframe.
(b) Add the list [1, 2, 3, 4, 5] to dataframe and display it.
Create a dataframe of [23, 25], [34], [43, 44, 45, 46] and do the following: :
(a) Display the dataframe. Notice that the missing value is represented by NaN.
(b) Replace the missing value with 0.
(c) Replace the missing value with -1, -2, -3, -4 for columns 0, 1, 2, 3.
(d) Replace the missing value by copying the value from the above cell.
Create a dataframe of {‘A’ : [ ]} and display whether it is empty or not.
Create a dataframe of {‘A’ : [5, 6], ‘B’: [3, 0], 'C': [0, 0]} and display the result of all() and any() functions.