1# Basic syntax:
2df['column'].value_counts()
3
4# Get normalized counts:
5df['column'].value_counts(normalize=True)
6
7# Example usage:
8# Make dataframe
9import pandas as pd
10df = pd.DataFrame(np.array([[1, 2, 3], [4, 5, 6], [7, 5, 9]]),
11 columns=['a', 'b', 'c'])
12
13print(df)
14 a b c
150 1 2 3
161 4 5 6
172 7 5 9
18
19df['b'].value_counts() # Returns:
205 2 # 5 appears twice in column 'b'
212 1
22
23df['b'].value_counts(normalize=True) # Returns:
245 0.666667 # 5 accounts for 2/3 of the entries in column 'b'
252 0.333333
1print df
2 col1 education
30 a 9th
41 b 9th
52 c 8th
6
7len(df[df['education'] == '9th'])
1print df
2 col1 education
30 a 9th
41 b 9th
52 c 8th
6
7print df.education == '9th'
80 True
91 True
102 False
11Name: education, dtype: bool
12
13print df[df.education == '9th']
14 col1 education
150 a 9th
161 b 9th
17
18print df[df.education == '9th'].shape[0]
192
20print len(df[df['education'] == '9th'])
212