查找数据框的所有可能组合

我有这样的数据:


     Price  Web  Destinations  Airport  Flight  Afterflight  Global

0      1    1             0        0       0            0       0

1      1    1             1        1       1            1       1

2      1    1             1        1       0            1       1

3      0    1             0        0       0            0       0

4      0    0             0        0       0            0       0 

我想找到除 Global 之外的所有变量的可能组合,并计算每个组合的实例数。有人可以帮我吗?


Smart猫小萌
浏览 177回答 1
1回答

侃侃尔雅

您可以使用GroupBy+ size:res = df.groupby(df.columns[:-1].tolist()).size().rename('Count').reset_index()print(res)   Price  Web  Destinations  Airport  Flight  Afterflight  Count0      0    0             0        0       0            0      11      0    1             0        0       0            0      12      1    1             0        0       0            0      13      1    1             1        1       0            1      14      1    1             1        1       1            1      1您的示例并不有趣,因为所有组合都是唯一的。
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

Python