-1

I have a list having multiple items

result = *json_formatted*
print(result) <-- [{'id: 1', value: array([10,11,12])}, {id: 2, value: array([20,21,22]) }] 

I am struggling to get this as a dataframe. I'd like my output to look like

id value
1 10
1 11
1 12
2 20
2 21
2 22
Moulldar
  • 63
  • 9

1 Answers1

2

Considering this to be your result:

In [940]: import numpy as np
In [941]: result = [{'id': 1, 'value': np.array([10,11,12])}, {'id': 2, 'value': np.array([20,21,22]) }] 

You can use df.explode: (available in pandas version > 0.25, as @Shijith pointed out)

In [952]: import pandas as pd
In [946]: df = pd.DataFrame(result)
In [950]: df = df.explode('value')

In [951]: df
Out[951]: 
   id value
0   1    10
0   1    11
0   1    12
1   2    20
1   2    21
1   2    22
Mayank Porwal
  • 33,470
  • 8
  • 37
  • 58