I'm working with the following DataFrame containing .str
values
maturity_rating
0 NaN
1 Rated: 18+ (R)
2 Rated: 7+ (PG)
3 NaN
4 Rated: 18+ (R)
and I'm trying to fill the NaN values randomly with other Non-Null values present in the same column
My expected output is:
maturity_rating
0 Rated: 7+ (PG)
1 Rated: 18+ (R)
2 Rated: 7+ (PG)
3 Rated: 18+ (R)
4 Rated: 18+ (R)
I tried using the following snippet
df["maturity_rating"].fillna(lambda x: random.choice(df[df['maturity_rating'] != np.nan]["maturity_rating"]), inplace =True)
However when I check for unique values, it fills NaN with a lambda object
df["maturity_rating"].unique()
Out[117]:
array([<function <lambda> at 0x7fe8d0431a60>, 'Rated: 18+ (R)',
'Rated: 7+ (PG)', 'Rated: 13+ (PG-13)', 'Rated: All (G)',
'Rated: 16+'], dtype=object)
Please Advise