Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

pandas replace nan with mean

--fillna
product_mean = df['product'].mean()
df['product'] = df['product'].fillna(product_mean)

--replace method
col_mean = np.mean(df['col'])
df['col'] = df['col'].replace(np.nan, col_mean)
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #pandas #replace #nan
ADD COMMENT
Topic
Name
9+8 =