我有一个包含3列id
,type
,type_value
的数据框。
它们已经填充了值。 type
列包含重复值type1
,type2
,type3
,type4
。
type_value
包含一个Counter对象,该对象中的出现频率很高。
我需要做的是在Counter字典上执行一些操作,并在type_value
与 type
匹配时更新type1
列,并保留其他行保持不变。
输入:
id type type_value
1 type1 Counter object that needs to be updated
2 type2 some random value
3 type3 some random value
4 type4 some random value
5 type1 Counter object that needs to be updated
6 type2 some random value
7 type3 some random value
8 type4 some random value
9 type1 Counter object that needs to be updated
10 type2 some random value
11 type3 some random value
12 type4 some random value
13 type1 Counter object that needs to be updated
14 type2 some random value
15 type3 some random value
16 type4 some random value
输出:
id type type_value
1 type1 Do an operation on this and update with new values
2 type2 some random value
3 type3 some random value
4 type4 some random value
5 type1 Do an operation on this and update with new values
6 type2 some random value
7 type3 some random value
8 type4 some random value
9 type1 Do an operation on this and update with new values
10 type2 some random value
11 type3 some random value
12 type4 some random value
13 type1 Do an operation on this and update with new values
14 type2 some random value
15 type3 some random value
16 type4 some random value
答案 0 :(得分:1)
按条件拟合行并应用您的自定义函数:
{{1}}