0

I have a dataframe which looks like this:

df

    date        x1_count    x2_count    x3_count    x4_count    x5_count    x6_count
0   2022-04-01  1981        0           0           0           0           0
1   2022-04-02  1434        1202        1802        1202        1102        1902
2   2022-04-03  1768        1869        1869        1869        1969        1189
3   2022-04-04  1823        1310        1210        1110        1610        1710
...
29  2022-04-30  1833        1890        1810        1830        1834        1870

I'm trying to create a histogram to see the distrubiton of values of each day, but the buckets of the histogram are too broad to see. How could I fix this?

Below is what I attempted:

df[['date','x1_count']].set_index(by='date').hist()

1 Answers1

0

You should be able to set the bins of the histogram manually with

df[['date','x1_count']].set_index(by='date').hist(bins=10)

By default the number of bins equals the number of unique dates. https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.hist.html

Edit: Depending on how you want to group the dates, you could also group them as such:

df.groupby(df["date"].dt.month).count().plot(kind="bar")

Can Pandas plot a histogram of dates?