找到所有可能的数据帧组合

2024-10-02 14:19:04 发布

您现在位置:Python中文网/ 问答频道 /正文

我有这样一个数据:

     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 

我想找出所有可能的变量组合,除了全局变量,并计算每个组合的实例数。谁能帮帮我吗?在


Tags: 数据实例webglobalpriceflight全局变量airport
1条回答
网友
1楼 · 发布于 2024-10-02 14:19:04

您可以使用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

你的例子并不有趣,因为所有的组合都是唯一的。在

相关问题 更多 >