我正在尝试按日期对数据框进行排序,如下所示:
result = result.sort_values(by=result.CF_FACT_DATFACT, ascending=True)
CF_FACT_DATFACT是一个 datetime64。通过执行这个命令我有这个错误:
KeyError Traceback (most recent call last) in () ----> 1 result = result.sort_values(by=result.CF_FACT_DATFACT, ascending=True)# group bills by client 按账单日期升序排序
/home/houssem/.local/lib/python2.7/site-packages/pandas/core/frame.pyc in sort_values(self,by,axis,ascending,inplace,kind,na_position)4717 4718 by = by [0] -> 4719 k = self._get_label_or_level_values(by, axis=axis) 4720 4721 if isinstance(ascending, (tuple, list)):
/home/houssem/.local/lib/python2.7/site-packages/pandas/core/generic.pyc in _get_label_or_level_values(self, key, axis) 1704
values = self.axes[axis].get_level_values(key)._values 1705
else: -> 1706 raise KeyError(key) 1707 1708 # 检查重复项密钥错误:0 2015-08-24 1 2016-04-01 2
2017-04-24 3 2017-03-10 4 2017-05-12 5
2018-02-02 6 2018-02-03 7 2018-03-04 8
2018-03-05 9 2018-03-07 10 2018-02-08 11
2018-04-12 12 2019-04-02 13 2019-04-03 14
2019-02-07 15 2019-03-09 16 2007 -04-06 17
2007-03-07 18 2007-02-11 19 2007-04-12 20
2009-04-08 21 2010-05-01 22 2010-02-03 23
2010-03-08 24 2011-03 -01 25 2011-02-12 26
2012-04-06 27 2012-03-07 28 2012-04-12 29
2013-04-02 ... 3617565 2010-04-10 3617566 2010-04-10 3617567 2011-08-02 3617568 2011-08-02 3617569 2011-08-06 3617570 36-751-08-016
2011-08-07 3617572 2011-06-10 3617573
2012-05-30 3617574 2012-05-05-30 3617575 2012-01-10 3617576
2012-01-10 3617577 2013-05-05-30 3617578 2013-05-05-30
3617579 2013 3617579 2013 361757175717571757175717580 -09-27 3617581 2014-01-30 3617582
2014-01-30 3617583 2015-03-02 3617584 2015-03-02 3617585
2009-03-07 3617586 2009-03-07 3617587 2013-06-02 3617588
2013-06 -02 3617589 2014-05-27 3617590 2014-05-27 3617591
2014-09-25 3617592 2014-09-25 3617593 2016-02-02 3617594
2016-02-02 Name: CF_FACT_DATFACT, Length: 3617595, dtype: datetime64[ ns]
我不明白这个问题,在对数据框进行排序时,重复值是否会引发错误?