【发布时间】:2015-07-02 18:57:48
【问题描述】:
我有一个数据框“dfm”:
match_x org_o group match_y
0 012 012 Smile Communications 92 012
1 012 012 Smile 92 000
2 10types 10TYPES 93 10types
3 10types 10types.com 97 10types
4 360works 360WORKS 94 360works
5 360works 360works.com 94 360works
我想要一个名为'tag'的'a'列。对于 dfm 中的每个组织,当 match_x 和 match_y 相等并且它们有一个唯一组时,标签将为“TP”,否则为“FN”。这是我使用的代码:
a['tag'] = np.where(((a['match_x'] == a['match_y']) & (a.groupby(['group', 'match_x','match_y'])['group'].count() == 1)),'TP', 'FN')
但我收到此错误:
TypeError: 'DataFrameGroupBy' object is not callable
有人知道怎么做吗?
【问题讨论】:
标签: python pandas group-by conditional-statements