遍历行时数据框值未更新

时间:2019-03-28 08:14:18

标签: python pandas

我对Pandas并不陌生,并且正在尝试使用它来分析大型数据集。我已经阅读了所有可以找到的内容,但无法正常工作。我正在尝试在数据框中逐行迭代的同时更新数据框中的值,但是在数据框中未更新这些值。

for index, row in df.iterrows():
    for j in data_column:
        this_value = some_value
        print(this_value) # prints some_value
        df.loc[index].at[j] = this_value
        print(df.loc[index].at[j]) # prints 0 (not updated)

1 个答案:

答案 0 :(得分:0)

使用DataFrame.at

df.at[index, j] = this_value

代替组合locat

df.loc[index].at[j] = this_value

但是iterrows仅用于某些特定的解决方案,更好的是使用一些替代方案。

Does iterrows have performance issues?

相关问题