how to get rid of “.0” in python

I have the dataframe df.info():

M   5899 non-null float64

I need to get rid of the .0 that the column M has.

df['M'].value_counts()

4354.0     4382
454.0        98
234324.0     98

I have tried df['M'].astype('int64') which gives me the same results as above.

What can I do to get rid of the decimal zero?

  • 1

    Did you assign df['M'] = df['M'].astype('int64') before running df['M'].value_counts()?

    – 

  • yes, actually the df[‘M’].value_counts() should be the last entry..

    – 

  • why would you want to get rid of the decimal place? Note that you have floating point numbers; so it’s a matter of display

    – 

  • I need the numbers as integers no float

    – 

  • There is no doubting that df['M'] = df['M'].astype('int64') will convert the column to int values. Are you sure you assign the converted column back to the column using df['M']=?

    – 




Leave a Comment