1

All data I try to take from this database comes out as string even though I have selected change to number on the Excel file.

import pandas as pd
import random
import matplotlib as plt
pdf= pd.read_csv('Campaign Feb 2023.csv', encoding="ANSI")
f= df["Total_Raised"]
x=int (f[3])

Error screen

jps
  • 20,041
  • 15
  • 75
  • 79

1 Answers1

3

Your data seems to contain numbers, where a comma (,) is used to mark the thousands. So 1,234,567 would be 1234567. Python cannot interpret these commas. The best way is to tell pandas to convert the numbers when reading the files. For this use thousands=',' as parameter of pd.read_csv:

df = pd.read_csv('Campaign Feb 2023.csv', thousands=",")
billy bud
  • 103
  • 2
  • 13
Corralien
  • 109,409
  • 8
  • 28
  • 52
  • Is the encoding parameter needed? This https://stackoverflow.com/a/22279431/9713633 says ansi is not supported in python – billy bud May 03 '23 at 12:29
  • @billybud. Thanks. The other parameters are not mandatory here actually, the important one is "thousands" after all. – Corralien May 03 '23 at 12:33