简体   繁体   中英

How to replace a null value from a pandas dataframe with a non-null value from the same column in the dataframe?

For example:

某组

I need to replace the NaN values for rows under HomePlanet column with the most frequent entries in the other rows (in this case it would be Earth). How can I go about executing this?

Is this what you are looking for (assuming your dataframe is named 'df')?

df["HomePlanet"].fillna("Earth", inplace = True)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM