I have a csv file, which have two columns are integers: count & vote
df = pd.read_csv('in.csv', sep='\t', encoding='utf8')
...
df.to_csv('out.csv', sep='\t', encoding='utf-8-sig', index=False)
What's strange is that the 'count' column is still integer in out.csv, but the 'vote' becomes floats, i.e. '2.0'. I want to keep it as original integer or str form of numbers, not floats, so I did:
df = df.applymap(str)
But it doesn't help at all. It still outputs floats, but also introduces new nan value for blank cell. How to output integer or str, not floats in the output csv?
CodePudding user response:
You can just specify a dtype for that column:
df = pd.read_csv(..., dtype={'vote': int}, ...)
Or use str instead of int, it depends on what you need those values for.
