fillna

Pandas Fillna Mode

霸气de小男生 提交于 2019-12-09 10:45:01
问题 I have a data set in which there is a column known as Native Country which contain around 30000 records. Some are missing represented by NaN so I thought to fill it with mode() value. I wrote something like this: data['Native Country'].fillna(data['Native Country'].mode(), inplace=True) However when I do a count of missing values: for col_name in data.columns: print ("column:",col_name,".Missing:",sum(data[col_name].isnull())) It is still coming up with the same number of NaN values for the

How to pass another entire column as argument to pandas fillna()

。_饼干妹妹 提交于 2019-11-26 00:37:59
问题 I would like to fill missing values in one column with values from another column, using fillna method. (I read that looping through each row would be very bad practice and that it would be better to do everything in one go but I could not find out how to do it with fillna .) Data before: Day Cat1 Cat2 1 cat mouse 2 dog elephant 3 cat giraf 4 NaN ant Data after: Day Cat1 Cat2 1 cat mouse 2 dog elephant 3 cat giraf 4 ant ant 回答1: You can provide this column to fillna (see docs), it will use