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

后端 未结 2 585
谎友^
谎友^ 2021-02-08 15:32

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:34

    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

    0 讨论(0)
  • 2021-02-08 16:34
    import locale, calendar
    # for example pl_PL
    locale.setlocale(locale.LC_ALL, 'pl_PL.UTF-8')
    x = x.rename_axis(lambda x: calendar.day_abbr[x].capitalize())
    
    0 讨论(0)
提交回复
热议问题