I have a list of numpy arrays and I am trying to merge them into a 2d matrix in the following way:
[arr1, arr2, arr3....]
arr1 = [0.24, 0.24, 0.56, 0.77]
arr2 = [0.1, 0.24]
arr3 = [0.6, 0.7, 0.72, 0.88]
This is what the output should look like:
NaN, 0.24, 0.24, 0.56, Nan, Nan, Nan, 0.77, Nan
0.1, 0.24, Nan, Nan, Nan, Nan, Nan, Nan, Nan
Nan, Nan, Nan, Nan, 0.6, 0.7, 0.72, NaN, 0.88
I use the following script to merge them:
# convert to series
series = [pd.Series(arr,index=arr) for arr in arrs]
# concat with reindex
pd.concat(series, axis=1)
But I run into the following error:
raise ValueError("cannot reindex from a duplicate axis")
ValueError: cannot reindex from a duplicate axis
Note that the input arrays have duplicates within them and I would like to keep those duplicates.
How do I go about fixing it?
EDIT:
given the discussion in the comments, the error is most likely arising due to duplicates and I was hoping to figure out a workaround that.
0.88, and what is the logic of placing0.77where it is?