value_counts()是一種查看表格某列中有多少個(gè)不同值的快捷方法,并計(jì)算每個(gè)不同值有在該列中有多少重復(fù)值。
value_counts()是Series擁有的方法刊棕,一般在DataFrame中使用時(shí),需要指定對(duì)哪一列或行使用
import pandas as pd
import numpy as np
filepath='C:\python\data_src\GFSCOFOG_03-05-2018 03-04-36-54_timeSeries\GFSCOFOG_CHA.csv'
data = pd.read_csv(filepath,encoding='utf-8')
數(shù)據(jù)樣例如下圖所示
image
查看Unit Name中有哪些不同的值,并計(jì)算每個(gè)值有多少個(gè)重復(fù)值
data['Unit Name'].value_counts()
data['Unit Name'].value_counts()
#輸出
Percent of GDP 3561
Domestic currency 3561
Percent of total expenditure 470
Name: Unit Name, dtype: int64
查看Sector Name中有哪些不同的值酪夷,并計(jì)算每個(gè)值有多少個(gè)重復(fù)值
data['Sector Name'].value_counts()
data['Sector Name'].value_counts()
#輸出結(jié)果
Extrabudgetary central government 1020
Social security funds 1002
Central government (incl. social security funds) 944
Budgetary central government 944
Local governments 944
General government 944
Central government (excl. social security funds) 944
State governments 850
Name: Sector Name, dtype: int64
作者:tommyjex
鏈接:http://www.reibang.com/p/f773b4b82c66
來源:簡(jiǎn)書
簡(jiǎn)書著作權(quán)歸作者所有,任何形式的轉(zhuǎn)載都請(qǐng)聯(lián)系作者獲得授權(quán)并注明出處孽惰。