0

I have a Pandas DataFrame that includes a column with in each row a Numpy array of fixed length (say 30) with integers. However, I cannot find a way to split the np array and for each integer in the array, create a new DataFrame column 0 ... 29.

For example (C consists of np.ndarrays):

   A  B  C
1  0  0  [0,3,4,...]
2  1  1  [0,1,2,...]
3  2  2  [3,4,5,...]
4  3  3  [5,6,7,...]

Should be:

   A  B  0  1  2  ... 29
1  0  0  0  3  4  ...
2  1  1  0  1  2  ...
3  2  2  3  4  5  ...
4  3  3  5  6  7  ...

I can do it for one array s by doing pd.DataFrame(s).T, but not for every row at once (by using something like apply()).

Is there a general solution, if a column would consist of lists instead of np array?

Icyeval
  • 113
  • 2

0 Answers0