Informatics Practices
Create a dataframe of {‘A’ : [ ]} and display whether it is empty or not.
Python Data Handling
3 Likes
Answer
import pandas as pd
df = pd.DataFrame({'A': []})
print(df)
if df.empty:
print("The dataframe is empty.")
else:
print("The dataframe is not empty.")
Output
Empty DataFrame
Columns: [A]
Index: []
The dataframe is empty.
Answered By
1 Like
Related Questions
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 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.
Create a dataframe of {‘A’ : [5, 6], ‘B’: [3, 0], 'C': [0, 0]} and display the result of all() and any() functions.
Create a dataframe of {‘A’ : [True, True], ‘B’: [True, False], ‘C’: [False, False]} and display the result of all() and any().