Best way to generate day-of-week boxplots from a Pandas timeseries

后端 未结 2 1946
你的背包
你的背包 2021-02-08 15:39

i am trying to create a set of day-of-week boxplots for a timeseries (e.g. 5-minute temperature observations).

My code:

# ts is our timeseries
ts = df.S         


        
2条回答
  •  既然无缘
    2021-02-08 16:12

    1st Create data frame and use weekdays method to get days of week:

    import pandas as pd
    import numpy.random as random
    n=1000
    df = pd.DataFrame(random.randn(n), pd.date_range('2010-01-01', periods=n), columns=["data"])
    df['Dates'] = df.index
    df['week_days'] =df.index.weekday
    df
    

    now pivot that table so that the week_days are as columns (could also change the needdays to string formats of days but leaving that for you.

    x =df.pivot(index='Dates', columns='week_days', values='data')
    x.boxplot()
    

    enter image description here

提交回复
热议问题