Plotting Pandas Multiindex Series

Hello,

I am trying to plot a Pandas Series which is derived from a larger dataframe. The final Series is turned out to be something like this:

Out[23]: df
element  number year  week
RESERV   57   1968     1       938.0
                       2       938.0
                       3       938.0
                       4       938.0
                       5       938.0
                                 .
                                 .
                                 .
RESERV   57   1999    48      938.0
                      49      938.0
                      50      938.0
                      51      938.0
                      52      938.0
Name: RESERV 57, dtype: float64

The mutli-index is not datetime object (or any date-related values, just numbers for specific reasons). I want to plot the x-axis using the ‘year’ and ‘week’ values and y-axis with the values of the Series. The years should be shown only once in every 52 weeks.

How is it possible? I could not find anything like this…

Thanks,

Hi, and thanks for writing in.

This seems like more of a pandas issue. What I would do is create a single index rather than having a multi index with year. You can use df.reindex() to get rid of the hierarchy, and then generate a new column to contain the date. Then, you can simply access df['date'] and df['value'] in plotly, and set your axis settings to get the date you want displayed.

Hi Charley,

Thanks for the note. This seems the only approach now. It would be cool if dash could handle the MultiIndex Pandas Series/Dataframes as well.