Splitting timestamp column into separate date and time columns

后端 未结 7 712
执念已碎
执念已碎 2020-11-27 06:29

I have a pandas dataframe with over 1000 timestamps (below) that I would like to loop through:

2016-02-22 14:59:44.561776

I\'m having a har

相关标签:
7条回答
  • 2020-11-27 07:00

    If your timestamps are already in pandas format (not string), then:

    df["date"] = df["timestamp"].date
    dt["time"] = dt["timestamp"].time
    

    If your timestamp is a string, you can parse it using the datetime module:

    from datetime import datetime
    data1["timestamp"] = df["timestamp"].apply(lambda x: \
        datetime.strptime(x,"%Y-%m-%d %H:%M:%S.%f"))
    

    Source: http://pandas.pydata.org/pandas-docs/stable/timeseries.html

    0 讨论(0)
提交回复
热议问题