Python Pandas Counting the Occurrences of a Specific value -
i new both python , pandas bare me if silly question. trying find number of times value appears in 1 column.
i have made dataframe data = pd.dataframe.from_csv('data/dataset2.csv')
and want find number of times appears in column. how done?
i thought below, looking in education column , counting number of time ?
occurs.
the code below shows trying find number of times 9th
appears , error getting when run code
code
missing2 = df.education.value_counts()['9th'] print(missing2)
error
keyerror: '9th'
iiuc can create subset
of data condition , use shape
or len
:
print df col1 education 0 9th 1 b 9th 2 c 8th print df.education == '9th' 0 true 1 true 2 false name: education, dtype: bool print df[df.education == '9th'] col1 education 0 9th 1 b 9th print df[df.education == '9th'].shape[0] 2 print len(df['education'] == '9th') 2
Comments
Post a Comment