[英]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.我想遍历每一行,并且想要检查每列中的值是否为 NaN 如果是,那么我想用不为空的同一行的前一个值替换它。
I believe the prefer way would be using lamba function.我相信更喜欢的方法是使用lamba函数。 But still not figure out to code it Note: I have thousands of rows and 200 columns in each row但仍然不知道编码它注意:我有数千行和每行 200 列
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)?您能否澄清您想在第一列中对 NaN 做什么?
我想你可以用这个 -
your_df.apply(lambda x : x.fillna(method='ffill'), axis=1)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.