Assume I have a DataFrame sales of timestamp values:
sales
timestamp sales_office 2014-01-01 09:01:00 Cincinnati 2014-01-01 09:11:00
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