Home > Mobile >  I am trying to convert csv into xlsx fileI am getting an error "No columns to parse from file&q
I am trying to convert csv into xlsx fileI am getting an error "No columns to parse from file&q

Time:04-21

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

CodePudding user response:

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

CodePudding user response:

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

  • Related