Original Source Here
The price column contains some missing values. How can we replace these missing values with the average price of the product? Please note that we should not fill the missing values with the average value of the price column. The missing values for apples need to be filled with the average price of apples, and so on.
There are multiple ways of doing this operation. One of the most practical options is to use the
groupby function inside the
Let’s first check the average price of each product.
Name: price, dtype: float64
We cannot use this line of code inside the
fillna function though. Instead, we will change it slightly by adding the
grocery["price_new"] = grocery['price'].fillna(
Let’s check the results by comparing the missing values in the price column with the values in the new column.
Trending AI/ML Article Identified & Digested via Granola by Ramsey Elbasheer; a Machine-Driven RSS Bot