IFRCGo / go-api

MIT License
14 stars 6 forks source link

Grouped/nonGrouped CSV output by default #2274

Open szabozoltan69 opened 1 month ago

szabozoltan69 commented 1 month ago

Instead of https://github.com/IFRCGo/go-api/blob/develop/per/custom_renderers.py#L9 we should make possible to use a new argument for CSV download, grouped / non-grouped, to have narrow CSV output.

A solution might be via:

import pandas as pd
data = [
    {'a': 'value1', 'b': 'value2', 'c': ['c1', 'c2', 'c3'], 'f': 'value4'},
    {'a': 'value5', 'b': 'value6', 'c': ['c4', 'c5'], 'f': 'value7'}
]
df = pd.DataFrame(data)
df_exploded = df.explode('c')
df_exploded = df_exploded[['a', 'b', 'c', 'f']]
df_exploded.to_csv('output.csv', index=False)

Or, the DEEP solution might be considered.

szabozoltan69 commented 1 month ago

@samshara @batpad