I’ve been working with data imported from a CSV. Pandas changed some columns to float, so now the numbers in these columns get displayed as floating points! However, I need them to be displayed as integers or without comma. Is there a way to convert them to integers or not display the comma?
Advertisement
Answer
To modify the float output do this:
JavaScript
x
25
25
1
df= pd.DataFrame(range(5), columns=['a'])
2
df.a = df.a.astype(float)
3
df
4
5
Out[33]:
6
7
a
8
0 0.0000000
9
1 1.0000000
10
2 2.0000000
11
3 3.0000000
12
4 4.0000000
13
14
pd.options.display.float_format = '{:,.0f}'.format
15
df
16
17
Out[35]:
18
19
a
20
0 0
21
1 1
22
2 2
23
3 3
24
4 4
25