How do I count each group in a DataFrame then append the group counts into a Summary DataFrame?
I'm very new to Python
I have set up an empty DataFrame
Counts_data=pd.DataFrame(columns=['filename','Green','Stubble','Baresoil','Stones','Shadow'])
I then start a For loop through images Inside the loop I create a DataFrame of RGBgroups.(Results predicted from the pixels RGB by a knn model)
df_img_pred=pd.DataFrame(knn.predict(df_img_data),columns=['RGBgroup'])
print(df_img_pred.head())
Img_counts=df_img_pred.stack().value_counts()
The output is
RGBgroup
0 BareSoil
1 Stubble
2 Stubble
3 Stubble
4 BareSoil
BareSoil 56507
Stubble 52751
Shadow 5030
Stones 4267
Green 245
dtype: int64
I want to count each group and append the results into the "Counts_data" Dataframe along with the filename of image. I've tried numerous ways of filtering, counting and append but I can't get it to work.
Any assistance would be greatly appreciated.