我有一个数据帧df,它有两列,分别是Rule\ ID和Location。它有如下数据-
Rule_ID Location
[u'2c78g',u'df567',u'5ty78'] US
[u'2c78g',u'd67gh',u'df890o'] India
[u'd67gh',u'df890o',u'5ty78'] Japan
[u'2c78g',u'5ty78',u'df890o'] US
我想要两个结果。每个位置的一个唯一规则ID计数。这里看起来应该是-
Location Count_of_unique_rule_ids
US 4
India 3
Japan 3
其次,我要按位置计算规则ID。在这里它看起来像-
Rule_ID Count Location
u'2c78g' 2 US
u'df567' 1 US
u'5ty78' 2 US
等等!你知道吗
这是问题的扩展-Manipulating data frames
您需要将数据帧转换为长格式(unnest columnRule\ID),然后直接进行总结:
这里有一条路
使用
apply
-
细节
x.sum()
在链表连接它们时,可以通过对链表集合进行计数来获得唯一的计数。你知道吗在列表上应用
pd.Series
将创建新行,然后在位置和度量上应用groupby
。你知道吗相关问题 更多 >
编程相关推荐