pyjstat icon indicating copy to clipboard operation
pyjstat copied to clipboard

Can not parse json-stat to Dataframe :: Using a json-stat generated by pyjstat :: There and (not) back again

Open acmeguy opened this issue 1 year ago • 3 comments

Line 394: output = pd.DataFrame([category + [values[i]] for i, category in enumerate(get_df_row(dimensions, naming))]) output = pd.DataFrame([category + [values[i]] ~~~~~~^^^ IndexError: list index out of range

dim_names = ['timestamp', 'OBJECTNO']

acmeguy avatar Nov 04 '23 11:11 acmeguy

len([i for i, category in enumerate(get_df_row(dimensions, naming))]), len(values) gives: (11274, 9360)

the enumerate is a lot longer than the values

acmeguy avatar Nov 04 '23 11:11 acmeguy

This round trip fails:

js_dataset = pyjstat.Dataset.read(some_df) another_df = js_dataset.write('dataframe')

acmeguy avatar Nov 04 '23 14:11 acmeguy

Another version of a failing roundtrip:

testcase

df_some = pd.DataFrame([
    {'Date': '2007-01-01', 'Variables': 'Gasolina 95 E5 Premium', 'value': 1.555},
    {'Date': '2007-01-01', 'Variables': 'Gasolina 98 E5 Premium', 'value': 1.681},
    {'Date': '2007-01-03', 'Variables': 'Gasolina 95 E5 Premium', 'value': 1.991},
    {'Date': '2007-01-03', 'Variables': 'Gasolina 98 E5 Premium', 'value': 1.991},
    {'Date': '2007-01-03', 'Variables': 'Gasolina 98 E5 Premium', 'value': 1.991}
])

test_a = pyjstat.Dataset.read(df_some)
test_a_js = test_a.write()
test_b = pyjstat.Dataset.read(test_a_js)
test_b_df = test_b.write('dataframe'). # fails

acmeguy avatar Nov 04 '23 15:11 acmeguy