Chartjs-How to convert pandas dataframe to specific json format

0👍

You could solve it like so:

df = df.set_index('month')
out = {'labels': df.index.tolist(), 'datasets': []}
for col in df.columns:
    out['datasets'].append({
        'label': col,
        'data': df[col].values.tolist()
    })

Leave a comment