1

My code :

 df=pd.read_csv("File.csv",header=None,delim_whitespace=True)
    df.to_excel("output.xlsx",sheet_name=sheet.name,index=False)

i can see File.csv has no data.How to avoid this error.(Data was extracted as csv format and saving in it as File.csv)

Error :

No Columns to parse from file
Sparrow
  • 15
  • 6

2 Answers2

0

After reading File.csv, check if the dataframe is empty:

if df.empty:
    ...

See How to check whether a pandas DataFrame is empty? for other approaches

congusbongus
  • 13,359
  • 7
  • 71
  • 99
  • thanks..I tried the alter way like if df is empty then print the name else it convert into excel file..But still getting same error – Sparrow Apr 20 '22 at 07:11
0

First of all you need to check what are your separators. https://pandas.pydata.org/docs/reference/api/pandas.read_csv.html

When using pandas separator parameter of read_csv fuction is by default ',' what are separators in your csv file? if they are for example semicolons, you need to specify it

  • Extracted data(File.csv) has no data in it.No seperator...I am reading multiple csv files...this is sample code.i am getting error on this – Sparrow Apr 20 '22 at 07:14
  • Then provide your code, not a 'sample one' - We can't figure the problem based on samples and not full informations – Andrzej Długosz Apr 20 '22 at 07:46