Say I have a dictionary with 10 key-value pairs. Each entry holds a numpy array. However, the length of the array is not the same for all of them.
How can I create a
In Python 3.x:
import pandas as pd import numpy as np d = dict( A = np.array([1,2]), B = np.array([1,2,3,4]) ) pd.DataFrame(dict([ (k,pd.Series(v)) for k,v in d.items() ])) Out[7]: A B 0 1 1 1 2 2 2 NaN 3 3 NaN 4
In Python 2.x:
replace d.items() with d.iteritems().
d.items()
d.iteritems()