How to check if a csv file is empty in pandas

0 votes
Jun 30, 2019 in Python by anonymous
14,733 views

2 answers to this question.

0 votes

Try this code:

import pandas as pd

df = pd.read_csv(filename)
if(df.empty):
    print ('CSV file is empty')
else:
    print ('CSV file is not empty')
answered Jul 1, 2019 by Esha
0 votes

Try this:

df = pd.DataFrame(columns=['Name', 'ID', 'Department'])
if df.empty == True:
print('DataFrame is empty')
else:
print('DataFrame is not empty')
answered Jul 1, 2019 by Bob

Related Questions In Python

+1 vote
1 answer

How to check if a string is in a file, using python?

Hi, Try the below given code: with open('myfile.txt') as ...READ MORE

answered Jul 5, 2019 in Python by Shabnam
• 930 points
2,027 views
0 votes
1 answer

How to check if any value is NaN in a Pandas DataFrame?

Hello @kartik, If you need to know how ...READ MORE

answered Jun 15, 2020 in Python by Niroj
• 82,840 points
4,280 views
+1 vote
1 answer

How to check if a string is null in python

Try this: if cookie and not cookie.isspace(): # the ...READ MORE

answered Aug 20, 2018 in Python by Priyaj
• 58,020 points
23,087 views
0 votes
1 answer

How do I check if a list is empty in python?

Hey @Vedant, that's pretty simple and straightforward: if ...READ MORE

answered May 28, 2019 in Python by Karthik
1,069 views
0 votes
1 answer

How to check whether a pandas DataFrame is empty?

Hello @kartik, I use the len function. It's much faster ...READ MORE

answered Apr 23, 2020 in Python by Niroj
• 82,840 points
1,980 views
0 votes
1 answer

How to check if an element is present in a Django queryset?

Hello @kartik, You can use the following code: if ...READ MORE

answered May 27, 2020 in Python by Niroj
• 82,840 points
14,911 views
0 votes
1 answer

How to check if a value exists in pandas dataframe index?

Hello @kartik, Basically instead of raising exception I ...READ MORE

answered Jun 15, 2020 in Python by Niroj
• 82,840 points
6,816 views
0 votes
1 answer

How to check if a float value(decimal number) is between range(0 to 10) in python

Hello,  A function that returns True for an integer number (int or ...READ MORE

answered Sep 14, 2020 in Python by Niroj
• 82,840 points
7,105 views
0 votes
1 answer

How to check if a list is empty in python?

To check if a list is empty ...READ MORE

answered May 27, 2019 in Python by Nisa
• 1,090 points
1,047 views
0 votes
1 answer

How to check if a substring is present in a string using Python?

To check if the substring exists in ...READ MORE

answered May 9, 2019 in Python by Sharan
1,140 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP