0

I have a sample CSV file in the path - /alb/alb_dev/alba/alb_dev/Fls/albb/at/conv in Winscp. When I'm trying to convert .csv file to .xlsx, I'm getting an error saying -

**AttributeError: module 'pandas' has no attribute 'read_csv'**

I tried running the below python code. Can anyone guide what mistake I'm making.

import os

os.chdir('/alb/alb_dev/alba/alb_dev/Fls/albb/at/conv')

import pandas as pd
 
# The read_csv is reading the csv file into Dataframe
 
df = pd.read_csv("./samplefile.csv")
 
# then to_excel method converting the .csv file to .xlsx file.
 
df.to_excel("samplefile.xlsx", sheet_name="Testing", index=False`

Thanks!

I tried installing **pip install pandas ** and pip-autoremove pandas -y and **pip install pip-autoremove ** This did not work.

Also tried renaming the .csv file and ran the script but it didn't work.

I want to convert .csv file to .xlsx file without any error.

tdelaney
  • 73,364
  • 6
  • 83
  • 116
Sherin Shaziya
  • 127
  • 1
  • 7
  • 2
    `pandas` does indeed have a `read_csv` function. The other possibility is that you imported a different module unfortunately named "pandas". Any chance your script is called "pandas.py" or there is another script you've been working on with that name? If so, there's your problem. Right after `import pandas as pd` you could add the line `print(pd.__file__)` to see which .py file you really got. – tdelaney Nov 18 '22 at 06:05
  • 2
    As for writing questions... the problem is on the `pd.read_csv` line. The other stuff doesn't matter and should be removed from the script. You don't need to `chdir` or do anything after the read to get the error, so that stuff should be removed. – tdelaney Nov 18 '22 at 06:07
  • 1
    https://stackoverflow.com/questions/40554657/module-pandas-has-no-attribute-read-csv – Panda Kim Nov 18 '22 at 06:15

0 Answers0