I'm loading data from a csv file into pandas data frame, the column in the csv file contains these values:
1,2,3.4,5,6.2
The issue is that int values are changed to floats (I understand that this is because float will be the more general dtype), so it is read as:
df
value
0 1.0
1 2.0
2 3.4
3 5.0
4 6.2
I need to get all the values as they are in the csv file as strings.
I tried using pd.read_csv('filename.csv',dtype=str) or pd.read_csv('filename.csv',dtype=object) and they result to changing them to floats then str:
value
0 1.0
1 2.0
2 3.4
3 5.0
4 6.2
is there any way to read them as they are? i.e:
value
0 1
1 2
2 3.4
3 5
4 6.2
This is my test CSV (untitled.csv):
a,1
b,2
c,3.4
d,5
e,6.2
With the following code pd.read_csv('untitled.csv', dtype='str', header=None), I obtain:

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With