简体   繁体   中英

Using indexes to fill mean values in pandas dataframe

样本数据

Trying to populate the mean values in a dataframe having NaN values. Need to populate the dataframe only for certain rows and not all rows.

Sample Data set

   A    b     c    
0 100   52    555
1 25   144    552
2 NaN  555    555
3 323  NaN    785
4 515  551    125
5 741  471    Nan
6 111  Nan    Nan

Here I need to fill values only for rows numbered 5 and 6 with the mean of their respective columns and should ignore rows 3 and 4.

您可以在数据帧切片上使用fillna()函数

df.iloc[5:7].fillna(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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM