I would like to loop through a pandas dataframe's columns using a for loop to count the value based on the list given.
My_list =[ 'apple', 'orange', 'grapes' ]
I can do it with value_count() functions as given below to calculate frequency
df['Fruits']. value_count()
but I want to calculate using the for loop to iterate over dataframe to get count and average of the list given.
My_list =[ 'apple', 'orange', 'grapes' ]
Df:
Fruits value
apple 10
apple 20
orange 2
grapes 5
grapes 10
grapes 3
My output should be like this.
Fruits count average
apple 2 15
orange 1 2
grapes 3 6