简体   繁体   English

访问每一行并检查数据框中的每一列值

[英]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.

相关问题 检查数据框中的值是否存在于每一行的另一列中 - Check if value in dataframe exists in another column for each row 检查 dataframe 中的每一行和每一列,并用用户定义的 function 替换值 - check each row and column in dataframe and replace value with user define function 如何使数据框中的每一行每一列都有一个值? - How to make each row in dataframe have one value for each column? 检查熊猫数据帧的一列是否包含不同列的每一行的子字符串? - Check if a column of a pandas dataframe contains a substring for each row of a different column? 遍历 dataframe 中的每一行和每一列并对列值执行操作 - iterate through each row and column in dataframe and perform action on column value 用另一个列的每个值迭代数据框的一行的值 - iterate a value of a row of a dataframe with each value of a column in another 检查一列中的每个值与一个数据框中另一列的每个值 - Check each value in one column with each value of other column in one dataframe 如何为数据框中的每一行分配一个值到不同的列? - How can I assign a value to a different column for each row in a dataframe? 如何在数据框中拆分一列并将每个值存储为新行(以熊猫为单位)? - How to split a column in a dataframe and store each value as a new row (in pandas)? 为数据框中的每一行收集值为 True 的列名 - Collect the column name whose value is True for each row in dataframe
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM