简体   繁体   中英

Acces each row and check each column value in dataframe

我有看起来像这样的数据集

I want to iterate over each row and and want to check in each column if value is NaN if it is then i want to replace it with the previous value of the same row which is not null.

I believe the prefer way would be using lamba function. But still not figure out to code it Note: I have thousands of rows and 200 columns in each row

The following should do the work:

df.fillna(method='ffill', axis=1, inplace=True)

Can you please clarify what you want to be done with NaNs in first column(s)?

我想你可以用这个 -

your_df.apply(lambda x : x.fillna(method='ffill'), axis=1) 

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