Given the following pandas
DataFrame
, what is the idiomatic way to display a time series plot with discrete time buckets for each name category?
Name | Type |
---|---|
time | datetime64 |
name | object |
value | float64 |
My current solution requires a loop that extracts a DataFrame
and computes a max
aggregation for each name category.
import pandas as pd
import matplotlib.pyplot as plt
raw_df = pd.read_csv('...')
raw_df['time'] = raw_df['time'].astype('datetime64[ns]')
names = raw_df['name'].unique()
names.sort()
fig, ax = plt.subplots()
for name in names:
df = raw_df.query(f'name == "{name}"').set_index('time').resample('10T').max()
df.plot(ax = ax, label=name)