Skip to content

Instantly share code, notes, and snippets.

@LinuxIsCool
Created December 20, 2023 01:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LinuxIsCool/c75aaf3cc745ecbae47458c8b4936125 to your computer and use it in GitHub Desktop.
Save LinuxIsCool/c75aaf3cc745ecbae47458c8b4936125 to your computer and use it in GitHub Desktop.
Generating cadCAD style data
import numpy as np
import pandas as pd
import hvplot.pandas
labels = list('ABC')
states = 4
xs = 100
df = pd.DataFrame({'x': len(labels)*states*list(range(xs)), 'label': [l for l in labels for _ in range(states*xs)], 'State': len(labels)*[s for s in list(range(states)) for _ in range(xs)], 'Value': 0.52+np.random.rand(len(labels)*states*xs)})
df['Value'] = df.groupby(['label', 'State']).cumprod()['Value']
df
# Observe
df.hvplot(x='x', y='Value', by='label', groupby='State')
df.hvplot(x='x', y='Value', by='State', groupby='label')
df.hvplot(x='x', y='Value', by='label', row='State', shared_axes=False)
@LinuxIsCool
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment