I am trying to use pandas.Series.value_counts to get the frequency of values in a dataframe, so I go through each column and get values_count , which gives me a series:
I am struggling to convert this resultant series to a dict:
groupedData = newData.groupby('class')
for k, group in groupedData:
dictClass[k] = {}
for eachlabel in dataLabels:
myobj = group[eachlabel].value_counts()
for eachone in myobj:
print type(myobj)
print myobj
what I need is a dict :
{'high': 3909 , 'average': 3688, 'less': '182 , 'veryless' : 62}
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…