gpt4 book ai didi

python - Pandas - 计数项目

转载 作者:行者123 更新时间:2023-11-30 08:56:18 26 4
gpt4 key购买 nike

我需要将此信息传递到图表中,我需要每个月与数量进行比较。

    year    state   month   number  date
718 1998 Amazonas Janeiro 0.0 1998-01-01
719 1999 Amazonas Janeiro 3.0 1999-01-01
720 2000 Amazonas Janeiro 7.0 2000-01-01
721 2001 Amazonas Janeiro 3.0 2001-01-01
722 2002 Amazonas Janeiro 17.0 2002-01-01
723 2003 Amazonas Janeiro 158.0 2003-01-01
724 2004 Amazonas Janeiro 123.0 2004-01-01
725 2005 Amazonas Janeiro 44.0 2005-01-01
726 2006 Amazonas Janeiro 20.0 2006-01-01
727 2007 Amazonas Janeiro 37.0 2007-01-01
728 2008 Amazonas Janeiro 16.0 2008-01-01
729 2009 Amazonas Janeiro 9.0 2009-01-01
730 2010 Amazonas Janeiro 82.0 2010-01-01
731 2011 Amazonas Janeiro 53.0 2011-01-01
732 2012 Amazonas Janeiro 6.0 2012-01-01
733 2013 Amazonas Janeiro 37.0 2013-01-01
734 2014 Amazonas Janeiro 46.0 2014-01-01
735 2015 Amazonas Janeiro 35.0 2015-01-01
736 2016 Amazonas Janeiro 770.0 2016-01-01
737 2017 Amazonas Janeiro 65.0 2017-01-01

我有一个数据集,我需要对所有数据进行求和,例如,一月 = 5000,二月 = 6790

我尝试了 sum() 和 count(),但没有成功。

dt['month'].sum()

dt['month'].count()

最佳答案

您需要首先使用 groupby 函数对数据框进行分组:

例如:

dt.groupby('month')['number'].sum()

您之前执行此操作的方式只是对列进行求和,而不管其值如何。

关于python - Pandas - 计数项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59314943/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com