How to split a pandas dataframe or series by day (possibly using an iterator)

后端 未结 2 2035
耶瑟儿~
耶瑟儿~ 2021-01-08 00:17

I have a long time series, eg.

import pandas as pd
index=pd.date_range(start=\'2012-11-05\', end=\'2012-11-10\', freq=\'1S\').tz_localize(\'Europe/Berlin\')         


        
2条回答
  •  有刺的猬
    2021-01-08 00:45

    If you want to group by date (AKA: year+month+day), then use df.index.date:

    result = [group[1] for group in df.groupby(df.index.date)]
    

    As df.index.day will use the day of the month (i.e.: from 1 to 31) for grouping, which could result in undesirable behavior if the input dataframe dates extend to multiple months.

提交回复
热议问题