python - Replacing missing data in pandas.DataFrame not working -


I'm digging in it

I have a panda. Detafrem which column 'age in' scattered NaN ' value and the second column IsAlone has been created with value 1 or 0 on the basis of a private rule on the basis of that person was alone on that ship.

I am trying to change the NaN values ​​on the columns age for those people who were alone and the average age of those people with the aim in the same manner which was not alone based on just a rule NaN instead of values ​​to practice Pands Detafrem

I'm doing with them were alone: ​​

  df_train [(df_train.IsAlone.astype (bool) and df_train.Age.isnull ())] .ge = \ df_train [(df_train.IsAlone.astype (bool) & Amp; ~ df_train.Age.isnull ())]. Age Mean ()   

And the same way for those who were not alone: ​​

  df_train [(~ df_train.IsAlone.astype (bool) and df_train .ge.isnull ())]. Age = \ df_train [(~ df_train.IsAlone .sleeppe (bool) and ~ df_train.Age.isnull ())]. Age Pisces ()   

But it is not working at all, Column Age still has the same NaN value.

Any thoughts on this?

The problem is that the values ​​were changed on the copy of the original frame in the view document details:

when a Pands set value in the object, then chained indexing is said to be taking care to avoid needed.

To change the values ​​on the View the original frame you can:

  j = df_train.IsAlone. Astype (bool) & amp; Df_train.Age.isnull () I = df_train.IsAlone.astype (bool) & amp; ~ Df_train.Age.isnull () df_train.loc [j, 'age'] = df_train.loc [i, 'age']. Meaning ()    

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -