[英]Pandas -> GroupBy two columns adding size as third
What is the equivalent in pandas for the SQL statement: SQL语句的大熊猫等效项是什么:
SELECT key1,key2,count(1) FROM mytable GROUP BY key1,key2
Please notice: i can still access key1
and key2
independently as i iterate line-by-line... I couldn't manage to it via 请注意:当我逐行迭代时,我仍然可以独立访问key1
和key2
...我无法通过它来管理它
myDataFrame.groupBy(by=['key1','key2']).size()
The above code prints the keys and the count of occurrences but i can't access the keys individually 上面的代码打印了键和出现次数,但我无法单独访问键
How does that query translates to pandas? 该查询如何转换为熊猫?
添加reset_index()
myDataFrame.groupBy(by=['key1','key2']).size().reset_index()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.