熊猫:时间戳转换为YYYY-MM-DD

时间:2019-06-25 06:26:40

标签: python pandas

我不断得到这些结果:

Comparator<SelectItem> comparator = new Comparator<SelectItem>() {
  @Override
  public int compare(SelectItem o1, SelectItem o2) {
    return Integer.compare(Integer.parseInt(o1.getLabel()), Integer.parseInt(o2.getLabel()));
  }
};

但是,我的目标是获得以下结果:

0   2019-02-28 19:24:18.101586+00:00
1   2019-03-01 08:33:15.668978+00:00
[...]
Name: created, dtype: datetime64[ns, UTC]

您看到我在做什么吗?

0   2019-02-28
1   2019-03-01

1 个答案:

答案 0 :(得分:1)

如果需要无时间限制的日期时间,请将Series.dt.tz_localizeSeries.dt.floor配合使用:

tickets['created'] = tickets['created'].dt.tz_localize(None).dt.floor('d')
print (tickets)
     created
0 2019-02-28
1 2019-03-01

print (tickets.dtypes)
created    datetime64[ns]
dtype: object
相关问题