[英]Pandas series index datetime sort
I'm trying to sort a Pandas Series which has dtype=<M8[ns
我正在尝试对
dtype=<M8[ns
Yet, the sorting goes well for the first few entries, and then becomes quite random. 但是,对于前几个条目,排序很顺利,然后变得非常随机。
I'm using this code 我正在使用此代码
d_series = pd.Series(dates_count)
d_series.index = pd.to_datetime(d_series.index)
d_series.sort_index(inplace=True)
d_series
The specific issue is here: 具体问题在这里:
2018-11-04 3
2018-11-06 338
2018-11-07 319
Since we didn't have those months yet. 因为我们还没有那几个月。 To confirm that the date-notation is not different from what I expect, this is how the series starts:
为了确认日期符号与我期望的没有什么不同,这是该系列的开始方式:
2018-03-15 2
2018-03-21 1
2018-03-22 1
As you can tell, the formatting is 'yyyy/mm/dd' but somehow going wrong. 如您所知,格式为“ yyyy / mm / dd”,但不知何故。
The problem was that I did not specify how to sort the dates, so I think the best guess was wrong. 问题是我没有指定如何对日期进行排序,所以我认为最好的猜测是错误的。 By defining the format, it was fixed.
通过定义格式,它是固定的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.