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
A NumPy array can be converted into a Pandas series by passing it in the pandas. Series() function.
Pandas expands on NumPy by providing easy to use methods for data analysis to operate on the DataFrame and Series classes, which are built on NumPy's powerful ndarray class.
The essential difference is the presence of the index: while the Numpy Array has an implicitly defined integer index used to access the values, the Pandas Series has an explicitly defined index associated with the values.
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]})
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With