I have an images data set which I have converted into NumPy array and getting total counts of pixels in individual images. I am using below code for this purpose:
data_custom_script = images data_custom_script = np.array(data_custom_script) import pandas as pd for images in data_custom_script: colours, counts = np.unique(images.reshape(-1,3), axis=0, return_counts=1) #giving these conditions because array has different shapes if counts.shape[0] == 7: counts = np.reshape(counts,(1,7)) if counts.shape[0] == 6: counts = np.reshape(counts,(1,6)) if counts.shape[0] == 5: counts = np.reshape(counts,(1,5)) if counts.shape[0] == 4: counts = np.reshape(counts,(1,4)) if counts.shape[0] == 3: counts = np.reshape(counts,(1,3))
Now when I run this code i get result into multiple 1D array for each images like this: enter image description here
Now when I convert this into data frame I got results in the form of individual data frames rather than one
df = pd.DataFrame(counts) print(df)
I want to get results in the form of a single data frame like this enter image description here
(1,7)
makes a 2d array, displayed as[[1 2 3]]
. If you really want that you don't need all theif
, just docounts = counts[None,:]
orcounts=counts.reshape(1,-1)
. Also, you don't show how you collect thecounts
in the iteration.