从熊猫数据框中删除小数

时间:2019-09-04 21:01:01

标签: python pandas

我有数字

24.00

2.00

3.00

我想要

24 

2 

3

我使用了.astype(int),round(),但是我一直在使用前一种。如何使它工作?

2 个答案:

答案 0 :(得分:1)

您需要重新分配table.test1 (也就是说,我想您的错误是):

dataframe

答案 1 :(得分:1)

您可以通过将熊猫optionprecision设置为0来解决此问题。

import pandas as pd
df = pd.DataFrame(data={"col": [24.00, 2.00, 3.00]})
print(df)
    col
0  24.0
1   2.0
2   3.0
pd.set_option('precision',0)
print(df)
   col
0   24
1    2
2    3