16

I would like to have the 3 columns of a numpy array

px[:,:,0]
px[:,:,1]
px[:,:,0]

into a pandas Dataframe.

Should I use?

df = pd.DataFrame(px, columns=['R', 'G', 'B'])

Thank you

Hugo

Hugo
  • 1,558
  • 12
  • 35
  • 68

1 Answers1

24

You need to reshape your array first, try this:

px2 = px.reshape((-1,3))
df = pd.DataFrame({'R':px2[:,0],'G':px2[:,1],'B':px2[:,2]})
Alvaro Fuentes
  • 16,937
  • 4
  • 56
  • 68