Skip to content Skip to sidebar Skip to footer

Concatenating Dictionaries Of Numpy Arrays Of Different Lengths (avoiding Manual Loops If Possible)

I have a question similar to the one discussed here Concatenating dictionaries of numpy arrays (avoiding manual loops if possible) I am looking for a way to concatenate the values

Solution 1:

One way is to go is use a dictionary of Series (i.e. the values are Series rather than arrays):

In [11]:d2Out[11]: {'r':array([ 0.3536318 ,  0.29363604,  0.91307454]), 's':array([46])}

In [12]:d2= {name:pd.Series(arr)forname, arrind2.iteritems()}

In [13]:d2Out[13]:
{'r':00.35363210.29363620.913075dtype:float64,
 's':046dtype:int64}

That way you can pass it into the DataFrame constructor:

In [14]: pd.DataFrame(d2)
Out[14]:
          r   s
00.3536324610.293636 NaN
20.913075 NaN

Post a Comment for "Concatenating Dictionaries Of Numpy Arrays Of Different Lengths (avoiding Manual Loops If Possible)"