I have a dataframe problem_data which has NaN values in some cells. I ran the following code.
problem_data[problem_data['level_type'] == 5.0]
It resulted to this :
problem_id level_type points tags
5 prob_1479 5.0 NaN NaN
31 prob_2092 5.0 NaN NaN
38 prob_4395 5.0 NaN combinatorics,constructive algorithms,dfs
43 prob_5653 5.0 NaN NaN
48 prob_2735 5.0 2750.0 NaN
52 prob_1054 5.0 2000.0 combinatorics,dp
64 prob_2610 5.0 NaN NaN
65 prob_1649 5.0 NaN NaN
70 prob_4675 5.0 NaN dp,games
74 prob_445 5.0 NaN NaN
81 prob_6481 5.0 2500.0 combinatorics,dp,implementation,number theory
134 prob_2964 5.0 2500.0 games
161 prob_948 5.0 2000.0 dp,games
182 prob_642 5.0 NaN NaN
Then, I ran the following command to fill the NaN of 'points' column.
problem_data.loc[problem_data['level_type'] == 5.0 , 'points'].fillna(value=2500, inplace=True)
When, I ran problem_data[problem_data['level_type'] == 5.0]
again, the output was same as before.
Can you tell why fillna()
didn't work here? What can I do to correct it?
fillna
does not work inplace on dataframe sub-slices. You'll want: