I have a Pandas dataframe that contains two type of columns, the ones that contain numpy arrays and the ones that contain floats.
E.g.:
arr1 f1
[0.3, 1.3] 3.5
I need to split the values of the arrays into rows.
If I only have these two columns, I can easily split the array like this:
df = pd.DataFrame([[x, j] for i, j in zip(a['arr1'], a['f1']) for x in list(i)], columns=['arr1', 'df1])
And the result looks like this:
arr1 f1
0.3 3.5
1.3 3.5
However, I can have any number of array and float columns, where the arrays in the same row always have the same length, i.e.: I can match all the elements of both arrays ((a1, b1), (a2, b2), ..., (a_n, b_n))
.
arr1 f1 arr2 f2
[0.3, 1.3] 3.5 [14.8, 1.2] 1.6
After splitting the arrays, the result should look like this:
arr1 f1 arr2 f2
0.3 3.5 14.8 1.6
1.3 3.5 1.2 1.6
It is easy to know what kind of data a column has, so that I can use zip accordingly, but anyway I can't figure out how to make it work for any number of columns.