2024-10-02 14:19:04 发布
网友
我有这样一个数据:
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
我想找出所有可能的变量组合,除了全局变量,并计算每个组合的实例数。谁能帮帮我吗?在
您可以使用GroupBy+size:
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
你的例子并不有趣,因为所有的组合都是唯一的。在
您可以使用
GroupBy
+size
:你的例子并不有趣,因为所有的组合都是唯一的。在
相关问题 更多 >
编程相关推荐