Multidimentional array to pandas dataframe

Question:

Suppose I have the following 4D array:

A = np.array([
            [[[0, 1, 2, 3],
              [3, 0, 1, 2],
              [2, 3, 0, 1],
              [1, 3, 2, 1],
              [1, 2, 3, 0]]],
            
            [[[9, 8, 7, 6],
              [5, 4, 3, 2],
              [0, 9, 8, 3],
              [1, 9, 2, 3],
              [1, 0, -1, 2]]]])

A.shape
(2, 1, 5, 4)

I want to transform it to the following DataFrame (with columns A,B,C,D):

   A    B    C    D
0  0    1    2    3
1  3    0    1    2
2  2    3    0    1
3  1    3    2    1
4  1    2    3    0
5  9    8    7    6
6  5    4    3    2
7  0    9    8    3
8  1    9    2    3
9  1    0   -1    2
Asked By: Amina Umar

||

Answers:

A possible solution:

pd.DataFrame(A.reshape(-1,4), columns = list('ABCD'))

Output:

   A  B  C  D
0  0  1  2  3
1  3  0  1  2
2  2  3  0  1
3  1  3  2  1
4  1  2  3  0
5  9  8  7  6
6  5  4  3  2
7  0  9  8  3
8  1  9  2  3
9  1  0 -1  2
Answered By: PaulS