Pandas: Return Hour from Datetime Column Directly

前端 未结 7 1831
我在风中等你
我在风中等你 2020-11-30 03:19

Assume I have a DataFrame sales of timestamp values:

timestamp               sales_office
2014-01-01 09:01:00     Cincinnati
2014-01-01 09:11:00         


        
7条回答
  •  遥遥无期
    2020-11-30 03:39

    Here is a simple solution:

    import pandas as pd
    # convert the timestamp column to datetime
    df['timestamp'] = pd.to_datetime(df['timestamp'])
    
    # extract hour from the timestamp column to create an time_hour column
    df['time_hour'] = df['timestamp'].dt.hour
    

提交回复
热议问题