我需要将此信息传递到图表,我需要每月与数量进行比较。
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
我有一个数据集,我需要将所有iten相加,例如,一月= 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/