Panda's replacement not possible

Asked 2 years ago, Updated 2 years ago, 94 views

I want to get rid of the 0 after the number

>>> ekfos_df.SPT
0      104.0
1          6
2         18
>>> ekfos_df.SPT.replace('.0', '')
0      104.0
1          6
2         18
>>> ekfos_df.SPT.str.replace('.0', '')
<input>:1: FutureWarning: The default value of regex will change from True to False in a future version.
0      NaN
1        6
2       18
>>> ekfos_df.loc[:, 'SPT'].replace('.0', '')
0      104.0
1          6
2         18
ekfos_df.loc[:, 'SPT'].str.replace('.0', '')
<input>:1: FutureWarning: The default value of regex will change from True to False in a future version.
0      NaN
1        6
2       18

I can't replace the string no matter how hard I try. What's the problem?

pandas replace

2022-09-20 10:29

1 Answers

>>> pd.__version__
'1.4.2'
>>> df
     SPT
0  104.0
1      6
2     18
>>> df.SPT
0    104.0
1        6
2       18
Name: SPT, dtype: object
>>> df.SPT.replace("\.0", "", regex=True)
0    104
1      6
2     18
Name: SPT, dtype: object
>>> 

I don't understand it either, but it works like this.


2022-09-20 10:29

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.