Home > Enterprise >  How to turn dataframe with categorical rows and numerical columns into coherent chart (sparkline lik
How to turn dataframe with categorical rows and numerical columns into coherent chart (sparkline lik

Time:01-21

After a bit of wrangling, I've got a dataframe that sort of looks like how it needs to be, with rows representing days of the week, and columns as weeks as they progress. I'd like to present each day as a timeseries plot, almost like a sparkline - but not sure how to do it. Can someone help?

(Here's my original question and thinking... enter image description here

This would be the line (except the gaps) to represent Wednesday's data. I do anticipate that I can fill the gaps over time using averaging.

CodePudding user response:

A simple way is to use relplot

Or with pure matplotlib:

import matplotlib.pyplot as plt

f, axes = plt.subplots(nrows=len(df), sharex=True)

for i, (name, s) in enumerate(df.set_index('week of year').iterrows()):
    axes[i].plot(s)
    axes[i].set_title(name)

output:

matplotlib

  •  Tags:  
  • Related