【问题标题】:Pandas series index datetime sort熊猫系列索引日期时间排序
【发布时间】:2019-02-19 10:44:36
【问题描述】:

我正在尝试对具有 dtype=<M8[ns 的 Pandas 系列进行排序

然而,前几个条目的排序很顺利,然后变得非常随机。

我正在使用此代码

d_series = pd.Series(dates_count)
d_series.index = pd.to_datetime(d_series.index)
d_series.sort_index(inplace=True)
d_series

具体问题在这里:

2018-11-04      3
2018-11-06    338
2018-11-07    319

因为我们还没有那几个月。为了确认日期符号与我的预期没有什么不同,这就是系列的开始方式:

2018-03-15      2
2018-03-21      1
2018-03-22      1

如您所知,格式为 'yyyy/mm/dd' 但不知何故出错了。

【问题讨论】:

  • 您的示例输出在我看来完全排序?
  • 除了你已经拥有的东西之外,你还期望什么?
  • 我们在 2018-11-04 没有参赛作品 :)
  • 谢谢大家,通过定义格式解决了这个问题。我曾假设如果它无法解析它会出错。我的坏:(

标签: python python-3.x pandas jupyter-notebook


【解决方案1】:

问题是我没有指定如何对日期进行排序,所以我认为最好的猜测是错误的。通过定义格式,它是固定的。

【讨论】:

    猜你喜欢
    • 2014-05-24
    • 2021-12-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-10-17
    • 1970-01-01
    • 1970-01-01
    • 2013-07-20
    相关资源
    最近更新 更多