我有个奇怪的熊猫问题。
我有个大师级的:
a b c
0 22 44 55
1 22 45 22
2 44 23 56
3 45 22 33然后,我有一个不同维度中的数据,其中包含了一些重叠索引和列名
index col_name new_value
0 a 111
3 b 234然后我想说,如果您在主数据文件中的索引和col_name上找到了匹配项,那么就替换该值。
所以输出将是
a b c
0 111 44 55
1 22 45 22
2 44 23 56
3 45 234 33我已经找到了"Combine_first“,但这是行不通的,除非我转向第二个数据帧(在这个场景中我不能这么做)
发布于 2018-12-27 16:36:28
这是update问题
df.update(updated.pivot(*updated.columns))
df
Out[479]:
a b c
0 111.0 44.0 55
1 22.0 45.0 22
2 44.0 23.0 56
3 45.0 234.0 33或
df.values[updated['index'].values,df.columns.get_indexer(updated.col_name)]=updated.new_value.values
df
Out[495]:
a b c
0 111 44 55
1 22 45 22
2 44 23 56
3 45 234 33https://stackoverflow.com/questions/53948103
复制相似问题