How can I use Ibis to fill missing values with the mean?
For example, if I have this data:
import pandas as pd
import ibis
from ibis import _
ibis.options.interactive = True
df = pd.DataFrame(data={'fruit': ['apple', 'apple', 'apple', 'orange', 'orange', 'orange'],
'variety': ['gala', 'honeycrisp', 'fuji', 'navel', 'valencia', 'cara cara'],
'weight': [134 , 158, pd.NA, 142, 96, pd.NA]})
t = ibis.memtable(df)
Using Ibis code:
- How would I replace the
NA
values in theweight
column with the overall mean ofweight
? - How would I replace the
NA
values in theweight
column with the the mean within each group (apples, oranges)?