аватар question@mail.ru · 01.01.1970 03:00

Python Pandas. Replace in the column some values ​​with others

The next task is the column Basepay1 The numbers are indicated in it, but the following values ​​are also found: not Provided . So, I need to transform this sign into the type of float64 .
I do the following: df ['Basepay']. Astype ('float64')
and I come out a mistake: could notch to float: 'not provideDed'

for obvious absolutely reasons) type of sign basepay object
the question is how to me in the sign basies not provideDD
replace for example at 0.00? This is the main question) I tried to write functions, nothing helps. I understand that the task is quite easy, but I will trample on one revenge on 3 hours.

аватар answer@mail.ru · 01.01.1970 03:00

Try using the method to replace 'not provideDed' with nan , for example.

  in [ 1 ]:  import  pandas  as  pdin [ 3 ]:  import  numpy  as  npin [ 5 ]: df = pd.dataframe ([ 0.1 ,  5.0 ,  'Not Provided' ], [ 'not Provided' ,  0.2  3.3 ]]) in [ 6 ]: dfout [ 6 ]:   0   1   2    0   0.1   5.0  not provideD  1  not Provided  0.2   3.3  in [ 7 ]: df.dtypesout [ 7 ]:   0   Object    1  float64  2   object  in [ 8 ]: result = df.Replace ( '' '"not personized' , np.nan) in [ 9 ]: resultronout [ 9 ]:   0   1   2    0   0.1   5.0  nan  1  nan  0.2   3.3  in [ 10 ]: result.dtypesout [ 10 ]:   0  float64  1  float64  2  float64dtype:  object                                        

Latest

Similar