Reputation: 139
I have a dataset containing a weight column, which I would like to subset while adjusting these weights to keep it representative of the original dataset.
Let us say I have the dataframe :
data.frame(Age=c(10,20,30,25,50,60,40),
Country=c("Germany","Germany","Germany","China","China","China","China"),
Class=c("A", "B", NA, NA, "B", "A", "A"),
Weight=c(1.1, 0.8, 1.2, 1.7, 0.7, 1.3, 0.9))
I would like to remove NA
rows in the column Class
, and update the Weight
column to keep my sample representative of the original dataset given the columns Age
and Country
. (The above dataframe may be too small for such question, but this is just for illustration).
Upvotes: 0
Views: 97
Reputation: 43
df.fillna(df.mean())
if want to fill Na values with mean or other specific value you can simply run this code.
data.fillna()
is use for fill nan values in pandas dataframe you can put value whatever you want to replace
Upvotes: 0