I have a dataframe having a column C, I want to fill consecutive blanks by the same number because later I need to group that row.
eg
A B C
1 2 Nan
1 2 Nan
1 2 3
1 2 Nan
1 2 Nan
the output I want is something like this
A B C
1 2 1
1 2 1
1 2 3
1 2 2
1 2 2
I tried using shift() to compare but didn't come to the desired output.
The function fillna is your solution:
dataframe['yourColumn'] = dataframe['yourColumn'] .fillna( 1 , inplace=True)
Moreover you can put whatever value you want to substitute the nan values. For instance, you coul set the mean:
dataframe['yourColumn']= dataframe['yourColumn'].fillna(dataset['yourColumn'] .mean(), inplace=True)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.