I have a dataset that follows this format:
data =[[[1, 0, 1000], [2, 1000, 2000]],
[[1, 0, 1500], [2, 1500, 2500], [2, 2500, 4000]]]
var1 = [10.0, 20.0]
var2 = ['ref1','ref2']
I want to convert it to a dataframe:
dic = {'var1': var1, 'var2': var2, 'data': data}
import Pandas as pd
pd.DataFrame(dic)
The result:
However I'm trying to get something like this:
I've been trying to flatten the dictionary/list but with no success:
pd.DataFrame([[col1, col2] for col1, d in dic.items() for col2 in d])
See the result:
The different sizes of the list made the 'unpacking' complicated for another level. I'm not sure if pandas could take care of this of it needs to be done before importing into pandas.