Splitting timestamp column into separate date and time columns

后端 未结 7 778
执念已碎
执念已碎 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 06:36

    Had same problem and this worked for me.

    Suppose the date column in your dataset is called "date"

    import pandas as pd
    df = pd.read_csv(file_path)
    
    df['Dates'] = pd.to_datetime(df['date']).dt.date
    df['Time'] = pd.to_datetime(df['date']).dt.time
    

    This will give you two columns "Dates" and "Time" with splited dates.

提交回复
热议问题