pandas in .value_counts () usage

Original link: https://www.jianshu.com/p/f773b4b82c66

value_counts () is a quick way to see how many different values in the table has a column, and different values are calculated for each number of duplicate values in the column.
value_counts () method has Series, when DataFrame generally used, it is necessary to specify which column or row, is returned by the function type Series, and different values for the index of the column, is the number of values of different values

1 import pandas as pd
2 import numpy as np
3 filepath='C:\python\data_src\GFSCOFOG_03-05-2018 03-04-36-54_timeSeries\GFSCOFOG_CHA.csv'
4 data = pd.read_csv(filepath,encoding='utf-8')

Sample data is shown below in FIG.

What are the different values ​​View Unit Name in there, and each value calculated how many duplicate values

data['Unit Name'].value_counts()

 

1 data['Unit Name'].value_counts()
2 #输出
3 Percent of GDP                  3561
4 Domestic currency               3561
5 Percent of total expenditure     470
6 Name: Unit Name, dtype: int64

See which different values ​​Sector Name in there, and each value calculated how many duplicate values

data['Sector Name'].value_counts()

 1 data['Sector Name'].value_counts()
 2 #输出结果
 3 Extrabudgetary central government                   1020
 4 Social security funds                               1002
 5 Central government (incl. social security funds)     944
 6 Budgetary central government                         944
 7 Local governments                                    944
 8 General government                                   944
 9 Central government (excl. social security funds)     944
10 State governments                                    850
11 Name: Sector Name, dtype: int64

 

Guess you like

Origin www.cnblogs.com/loubin/p/11297654.html
Recommended