0

I am quite new to Numpy and Python.

Two different shapes for an input array, it's either

  • 24, 18, 2431
  • 9, 17, 2431

How can I convert to a Pandas data frame without using Panel (It's removed from Pandas 0.25.0). The output should look something like

index | A | B | C

0 | A_value | B_value | C_value

1 | A_value | B_value | C_value

2 | A_value | B_value | C_value

3 | A_value | B_value | C_value

4 | A_value | B_value | C_value
Amr Yousef
  • 554
  • 1
  • 10
  • 27
  • The question is: how do you want to convert this: should it stop when the first array stops (so 18 rows for the first one, 9 for the second), or some sort of way to resolve this? – Willem Van Onsem Jul 27 '19 at 14:28
  • 1
    possible duplicate of https://stackoverflow.com/questions/36235180/efficiently-creating-a-pandas-dataframe-from-a-numpy-3d-array?rq=1 – Vinay Hegde Jul 27 '19 at 14:31
  • @WillemVanOnsem The thing is we can get different combinations so the idea is to have 24 x 18 x 2431 = 1,050,192 number of items in the data frame. – Amr Yousef Jul 27 '19 at 14:32
  • @VinayHegde Thanks so much for pointing this out. The answer used in the link your provided uses Panel which is removed in Pandas 0.25.0. – Amr Yousef Jul 27 '19 at 14:33
  • Possible duplicate of [Efficiently Creating A Pandas DataFrame From A Numpy 3d array](https://stackoverflow.com/questions/36235180/efficiently-creating-a-pandas-dataframe-from-a-numpy-3d-array) – basilisk Jul 27 '19 at 14:41
  • 1
    Is `(A, B, C)` supposed to be a shape? Because then your dataframe doesn't make sense, having dimension (sizes) as column header and values. – 9769953 Jul 27 '19 at 14:41
  • You may want to edit your question to indicate you can't or don't want to use `Panel` (since there are already two suggestions via a duplicate to use this). – 9769953 Jul 27 '19 at 14:43
  • 1,050,192 items in a DataFrame is a Series. Willem van Onsem's question effectively is, how do you want to reshape your 3D array into a 2D array? For example, will your DataFrame always have 2431 rows? – 9769953 Jul 27 '19 at 14:44
  • @00 I've edited the question to state that I should avoid `Panel`. My point for that `1,050,192` items is that I want to capture all the combinations that could make a row from this 3d array. – Amr Yousef Jul 27 '19 at 14:55
  • You need to give an example (for one or two small input arrays), of you want to achieve. "capture all the combinations that could make a row" is either a lot, or doesn't make sense. – 9769953 Jul 27 '19 at 15:08

0 Answers0