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

后端 未结 11 1279
轮回少年
轮回少年 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:35

    It depends on the data format the telephone number is stored.

    If it is in an numberic format changing to an integer might solve the problem

    df = pd.DataFrame({'TelephoneNumber': [123.0, 234]})
    df['TelephoneNumber'] =  df['TelephoneNumber'].astype('int32')
    

    If it is really a string you can replace and re-assign the column.

    df2 = pd.DataFrame({'TelephoneNumber': ['123.0', '234']})
    df2['TelephoneNumber'] = df2['TelephoneNumber'].str.replace('.0', '')
    

提交回复
热议问题