How do I convert a numpy array into a pandas dataframe?

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

Answers


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]})

Need Your Help

An object reference is required to access a non-static member

c# .net oop member static

I'm having this error come up and I'm not sure why... I've tried to look it up, people are saying to create an object of the class or create the methods as static... but I'm unsure how.

Finding common elements in two arrays of different size

c algorithm

I have a problem to find common elements in two arrays and that's of different size.