How pandas uses groupby to replace NaN values with averages… here is a solution to the problem.
How pandas uses groupby to replace NaN values with averages
I tried using it to
replace the NaN value in the column feature count (it is an integer ranging from 1 to 10), using groupby(client_id or client_name),
However, the NaN value does not seem to disappear.
df['feature_count'].isnull().sum()
The output is:
2254
Now I use:
df['feature_count'].fillna(df.groupby('client_name')['feature_count'].mean(), inplace=True)
But the output remains the same:
df['feature_count'].isnull().sum()
2254
Is there another way to replace NaN values with other non-NaN values for columns grouped by ID?