python - Creating dataframe from a dictionary where entries have different lengths - Stack Overflow

PHOTO EMBED

Sun Oct 18 2020 16:45:54 GMT+0000 (Coordinated Universal Time)

Saved by @arielvol #python

>>> mydict = {'one': [1,2,3], 2: [4,5,6,7], 3: 8}

>>> dict_df = pd.DataFrame({ key:pd.Series(value) for key, value in mydict.items() })

>>> dict_df

   one  2    3
0  1.0  4  8.0
1  2.0  5  NaN
2  3.0  6  NaN
3  NaN  7  NaN
content_copyCOPY

https://stackoverflow.com/questions/19736080/creating-dataframe-from-a-dictionary-where-entries-have-different-lengths