Pandas: Return Hour from Datetime Column Directly

前端 未结 7 1850
我在风中等你
我在风中等你 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:19

    Since the quickest, shortest answer is in a comment (from Jeff) and has a typo, here it is corrected and in full:

    sales['time_hour'] = pd.DatetimeIndex(sales['timestamp']).hour
    

提交回复
热议问题