How floor a date to the first date of that month?

后端 未结 8 1185
我寻月下人不归
我寻月下人不归 2021-01-01 17:43

I have a pandas DataFrame with index column = date.

Input:

            value
date    
1986-01-31  22.93
1986-02-28  15.46
8条回答
  •  死守一世寂寞
    2021-01-01 18:08

    Liked Mikhail Venkov answer. Added below code to have the column added as a timestamp value and keep timezone information

        df['month'] = pd.to_datetime(df['timestamp'].dt.strftime('%Y-%m-01')).dt.tz_localize(timezone) 
    

    where timezone = 'America/Los_Angeles' or whatever zone you want

提交回复
热议问题