我有这样的数据: Price Web Destinations Airport Flight Afterflight Global0 1 1 0 0 0 0 01 1 1 1 1 1 1 12 1 1 1 1 0 1 13 0 1 0 0 0 0 04 0 0 0 0 0 0 0 我想找到除 Global 之外的所有变量的可能组合,并计算每个组合的实例数。有人可以帮我吗?
1 回答

侃侃尔雅
TA贡献1801条经验 获得超16个赞
您可以使用GroupBy+ size:
res = df.groupby(df.columns[:-1].tolist()).size().rename('Count').reset_index()
print(res)
Price Web Destinations Airport Flight Afterflight Count
0 0 0 0 0 0 0 1
1 0 1 0 0 0 0 1
2 1 1 0 0 0 0 1
3 1 1 1 1 0 1 1
4 1 1 1 1 1 1 1
您的示例并不有趣,因为所有组合都是唯一的。
添加回答
举报
0/150
提交
取消