I am trying to sort a dataframe by date like this :
result = result.sort_values(by=result.CF_FACT_DATFACT, ascending=True)
CF_FACT_DATFACT is a datetime64. by executing this command I have this error :
KeyError Traceback (most recent call last) in () ----> 1 result = result.sort_values(by=result.CF_FACT_DATFACT, ascending=True)# group bills by client sort ascending by date of bill
/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 # Check for duplicatesKeyError: 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
2011-08-06 3617571 2011-06-10 3617572 2011-06-10 3617573
2012-05-30 3617574 2012-05-30 3617575 2012-01-10 3617576
2012-01-10 3617577 2013-05-30 3617578 2013-05-30 3617579
2013-09-27 3617580 2013-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]
I don't understand the problem, is the duplicated values raise errors when sorting a dataframe?
to fix this problem the by argument must take a string or a table of strings that indicate the columns on which I will apply the sort