Time-series boxplot in pandas

后端 未结 3 1857
庸人自扰
庸人自扰 2021-01-02 02:38

How can I create a boxplot for a pandas time-series where I have a box for each day?

Sample dataset of hourly data where one box should consist of 24 values:

3条回答
  •  情书的邮戳
    2021-01-02 03:13

    (Not enough rep to comment on accepted solution, so adding an answer instead.)

    The accepted code has two small errors: (1) need to add numpy import and (2) nned to swap the x and y parameters in the boxplot statement. The following produces the plot shown.

    import numpy as np
    import pandas as pd
    import seaborn
    import matplotlib.pyplot as plt
    
    n = 480
    ts = pd.Series(np.random.randn(n), index=pd.date_range(start="2014-02-01", periods=n, freq="H"))
    
    fig, ax = plt.subplots(figsize=(12,5))
    seaborn.boxplot(ts.index.dayofyear, ts, ax=ax)
    

提交回复
热议问题