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

后端 未结 8 1200
我寻月下人不归
我寻月下人不归 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条回答
  •  猫巷女王i
    2021-01-01 18:03

    there is a pandas issue about the floor problem

    the suggested way is

    import pandas as pd
    pd.to_datetime(df.date).dt.to_period('M').dt.to_timestamp()
    

提交回复
热议问题