我有一个模拟数据框,df1有6列5行,也就是说,有形状(5 x 6)
每列表示一个区域的价格,行表示时间
DK1 DK2 NO1 NO2 NO3 NO4
0 10 10 12 15 15 10
1 15 10 15 10 10 10
2 15 15 15 15 15 15
3 10 10 12 15 15 10
4 10 10 10 10 15 15
现在,我想在每一行中确定与第一列“DK1”价格相同的区域,然后能够总结出任何列组合相等的频率,这意味着我对此的期望输出为:
Combo Occurrence
0 DK1-DK2-NO4 2
1 DK1-DK2-NO1-NO2-NO3-NO4 1
2 DK1-NO1 1
3 DK1-DK2-NO1-NO2 1
优选地,该解决方案应适用于任何大小的数据帧。我开始尝试使用.apply()方法,但无法完全开始。希望你能帮忙
通过^{} 按第一列比较数据帧,然后使用^{} 与带分隔符的列名进行矩阵相乘,使用^{} 进行最后计数,并转换为
DataFrame
:编辑:对于组,可以通过所有值创建字典,然后调用
replace
:相关问题 更多 >
编程相关推荐