Get MM-DD-YYYY from pandas Timestamp

后端 未结 4 765
庸人自扰
庸人自扰 2020-12-05 08:02

dates seem to be a tricky thing in python, and I am having a lot of trouble simply stripping the date out of the pandas TimeStamp. I would like to get from 2013-09-29

4条回答
  •  渐次进展
    2020-12-05 08:25

    Maybe this only came in recently, but there are built-in methods for this. Try:

    In [27]: s = pd.Series(pd.date_range(pd.Timestamp('now'), periods=2))
    In [28]: s
    Out[28]: 
    0   2016-02-11 19:11:43.386016
    1   2016-02-12 19:11:43.386016
    dtype: datetime64[ns]
    In [29]: s.dt.to_pydatetime()
    Out[29]: 
    array([datetime.datetime(2016, 2, 11, 19, 11, 43, 386016),
       datetime.datetime(2016, 2, 12, 19, 11, 43, 386016)], dtype=object)
    

提交回复
热议问题