CBSE Class 12 Informatics Practices Question 39 of 44

Data Handling using Pandas — Question 40

Back to all questions
40
Question

Question 37

Create a dataframe of {‘A’ : [ ]} and display whether it is empty or not.

Solution
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.
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.