how to round/remove traling “.0” zeros in pandas column?

后端 未结 11 1287
轮回少年
轮回少年 2020-12-06 10:15

I\'m trying to see if I can remove the trailing zeros from this phone number column.

Example:

0
1      8.00735e+09
2      4.35789e+09
3      6.10644e         


        
11条回答
  •  不知归路
    2020-12-06 10:36

    Try str.isnumeric with astype and loc:

    s = pd.Series(['', 8.00735e+09, 4.35789e+09, 6.10644e+09])
    c = s.str.isnumeric().astype(bool)
    s.loc[c] = s.loc[c].astype(np.int64)
    print(s)
    

    And now:

    print(s)
    

    Outputs:

    0              
    1    8007350000
    2    4357890000
    3    6106440000
    dtype: object
    

提交回复
热议问题