将 nan 替换为值序列

数据挖掘 熊猫
2022-02-14 23:22:07

我有爱尔兰的 covid 测试数据集。五月的数据刚刚停止。

测试

为了延续这一趋势,我采用了上一个稳定时期的平均周一至周日。所以我有7个不同的平均值。

现在我想编辑数据集以从索引为“47545”的行中按顺序插入这些值。

我没有收到任何错误,也不会更改数据集。

ireland_df3 = ireland_df.copy()

ireland_df3[ireland_df3.reset_index().index % 7 == 47545]['new_tests_per_thousand'] = df1_mean
ireland_df3[ireland_df3.reset_index().index % 7 == 47546]['new_tests_per_thousand'] = df2_mean
ireland_df3[ireland_df3.reset_index().index % 7 == 47547]['new_tests_per_thousand'] = df3_mean
ireland_df3[ireland_df3.reset_index().index % 7 == 47548]['new_tests_per_thousand'] = df4_mean
ireland_df3[ireland_df3.reset_index().index % 7 == 47549]['new_tests_per_thousand'] = df5_mean
ireland_df3[ireland_df3.reset_index().index % 7 == 47550]['new_tests_per_thousand'] = df6_mean
ireland_df3[ireland_df3.reset_index().index % 7 == 47551]['new_tests_per_thousand'] = df7_mean

有任何想法吗?

1个回答

试试locor iloc,比如:

ireland_df3.iloc[47545, 'new_tests_per_thousand'] = df1_mean  

等等

你想对括号中的操作做什么?现在看起来它检查索引的 mod 7 是否等于 47545?这是没有意义的。