Numbers of Day in Month

后端 未结 4 913
再見小時候
再見小時候 2020-12-11 05:03

I have a data frame with a date time index, and I would like to multiply some columns with the number of days in that month.

                   TUFNWGTP  TEL         


        
4条回答
  •  清歌不尽
    2020-12-11 05:29

    import pandas as pd
    from pandas.tseries.offsets import MonthEnd
    
    df['dim'] = (pd.to_datetime(df.index) + MonthEnd(0)).dt.day
    

    You can omit pd.to_datetime(), if your index is already DatetimeIndex.

提交回复
热议问题