zoukankan      html  css  js  c++  java
  • pandas中.value_counts()的用法

    原文链接:https://www.jianshu.com/p/f773b4b82c66

    value_counts()是一种查看表格某列中有多少个不同值的快捷方法,并计算每个不同值有在该列中有多少重复值。
    value_counts()是Series拥有的方法,一般在DataFrame中使用时,需要指定对哪一列或行使用,该函数返回的也是Series类型,且index为该列的不同值,values为不同值的个数

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

    数据样例如下图所示

    查看Unit Name中有哪些不同的值,并计算每个值有多少个重复值

    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
     

    查看Sector Name中有哪些不同的值,并计算每个值有多少个重复值

    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
     
  • 相关阅读:
    POJ 2752 Seek the Name, Seek the Fame
    POJ 2406 Power Strings
    KMP 算法总结
    SGU 275 To xor or not to xor
    hihocoder 1196 高斯消元.二
    hihoCoder 1195 高斯消元.一
    UvaLive 5026 Building Roads
    HDU 2196 computer
    Notions of Flow Networks and Flows
    C/C++代码中的笔误
  • 原文地址:https://www.cnblogs.com/liuys635/p/12327268.html
Copyright © 2011-2022 走看看