Append a list of arrays as column to pandas Data Frame with same column indices Append a list of arrays as column to pandas Data Frame with same column indices pandas pandas

Append a list of arrays as column to pandas Data Frame with same column indices


Suggestion:

df_l = pd.DataFrame(l_) df_1['a_'] = pd.Series(a_list, index=df_1.index)

Example #1:

L = list(data)A = list(data)data_frame = pd.DataFrame(L) data_frame['A'] = pd.Series(A, index=data_frame.index)

Example #2 - Same Series length (create series and set index to the same as existing data frame):

In [33]: L = list(item for item in range(10))In [34]: A = list(item for item in range(10,20))In [35]: data_frame = pd.DataFrame(L,columns=['L'])In [36]: data_frame['A'] = pd.Series(A, index=data_frame.index)In [37]: print data_frame   L   A0  0  101  1  112  2  123  3  134  4  145  5  156  6  167  7  178  8  189  9  19

Example #3 - Different Series lengths (create series and let pandas handle index matching):

In [45]: not_same_length = list(item for item in range(50,55))In [46]: data_frame['nsl'] = pd.Series(not_same_length)In [47]: print data_frame   L   A  nsl0  0  10   501  1  11   512  2  12   523  3  13   534  4  14   545  5  15  NaN6  6  16  NaN7  7  17  NaN8  8  18  NaN9  9  19  NaN

Based on your comments, it looks like you want to join your list of lists.I'm assuming they are in list structure because array() is not a method in python. To do that you would do the following:

In [63]: A = [[381],[376], [402], [400]]In [64]: A = [inner_item for item in A for inner_item in item]In [65]: print A[381, 376, 402, 400]

Then create the Series using the new array and follow the steps above to add to your data frame.