value_counts()是一种查看表格某列中有多少个不同值的快捷方法,并计算每个不同值有在该列中有多少重复值。
value_counts()是Series拥有的方法,一般在DataFrame中使用时,需要指定对哪一列或行使用
import pandas as pdimport numpy as npfilepath='C:\python\data_src\GFSCOFOG_03-05-2018 03-04-36-54_timeSeries\GFSCOFOG_CHA.csv'data = pd.read_csv(filepath,encoding='utf-8')
数据样例如下图所示

数据样例
查看Unit Name中有哪些不同的值,并计算每个值有多少个重复值**
data['Unit Name'].value_counts()
data['Unit Name'].value_counts()#输出Percent of GDP 3561Domestic currency 3561Percent of total expenditure 470Name: Unit Name, dtype: int64
查看Sector Name中有哪些不同的值,并计算每个值有多少个重复值**
data['Sector Name'].value_counts()
data['Sector Name'].value_counts()#输出结果Extrabudgetary central government 1020Social security funds 1002Central government (incl. social security funds) 944Budgetary central government 944Local governments 944General government 944Central government (excl. social security funds) 944State governments 850Name: Sector Name, dtype: int64
