Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Data Science by (18.4k points)

How do I remove a Empty DataFrame, columns, and index line?

Here is my code:

df = pd.read_csv(filename)

   print(df)

   if df.empty:

      print("There is no data availale.")

Here are my results:

Empty DataFrame

Columns: [Date, Time, Name]

Index: []

There is no data availale.

I want those results to be just:

There is no data available.

1 Answer

0 votes
by (36.8k points)

Use len(df):

df = pd.read_csv(filename)

if len(df)<1:

    print("There is no data availale.")

else:

    print(df)

Want to be a master in Data Science? Enroll in this Data Scientist

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...