0

Im trying to remove the .0 present at the end of each number in the column M1 bis.

us_m1.head()

    DATE        M1      M1bis
0   1975-01-06  273.4   273400.0
1   1975-01-13  273.7   273700.0
2   1975-01-20  273.8   273800.0
3   1975-01-27  273.7   273700.0
4   1975-02-03  275.2   275200.0

I tried this but it is not doing anything, do you have some idea how I could do this ?

us_m1['M1bis'].replace(to_replace ='.0',value = 'None',inplace = True)

Thanks

Quant
  • 3
  • 2
  • actually those are in `float` format that's why you are having in that format just simply convert them into `int` using `astype` – Pygirl Feb 04 '21 at 17:28

2 Answers2

1

us_m1['M1bis'] = us_m1['M1bis'].astype(int) will change each to int and remove the value.

pandasman
  • 90
  • 18
-1

If your M1bis column is of type float pandasman solution will solve the issue.

If your column is of type string the following will do:

us_m1["M1bis"] = us_m1["M1bis"].apply(lambda x: x.replace(".0", "")

.apply iterates over each value in the column us_m1["M1bis"] lambda x: function(x) applies a function on each entry (x). replace(".0", "") replaces every .0 string with an empty one.

Janman
  • 67
  • 8