0

I have a csv available that lists numbers as follows:

4,872 ; 3,701 ; 2,018 ; 5,605 

Now I want to read this csv and use the following code:

for file in all_files:
    df = pd.read_csv(file, sep=";", thousands=',')

Unfortunately, the values are not listed as int, but as strings although I use "thousands=". E.g.:

' 3,701 ', ' 2,018 '

How do I fix the problem? Is it caused by the spaces?

MasseAlarm
  • 13
  • 7
  • you can remove the comma ```df['col'] = df['col'].str.replace(',', '')``` then convert the column to numeric: ```df['col'] = pd.to_numeric(df['col'])``` – khaled koubaa Sep 19 '22 at 12:28

0 Answers0