欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

關(guān)于Pandas?count()與values_count()的用法及區(qū)別

 更新時(shí)間:2022年05月12日 11:13:49   作者:Elvirangel  
這篇文章主要介紹了關(guān)于Pandas?count()與values_count()的用法及區(qū)別,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教

Pandas count()與values_count()用法

count()

values_count()在指定的統(tǒng)計(jì)的列名上

結(jié)果多了該列:

對(duì)比:

對(duì)比:

Pandas:count()與value_counts()對(duì)比

1. Series.value_counts(self, normalize=False, sort=True, ascending=False, bins=None, dropna=True)

返回一個(gè)包含所有值及其數(shù)量的 Series。 且為降序輸出,即數(shù)量最多的第一行輸出。

參數(shù)含義如下:

Parameters:

normalize : boolean, default False

If True then the object returned will contain the relative frequencies of the unique values.

sort : boolean, default True

Sort by frequencies.

ascending : boolean, default False

Sort in ascending order.

bins : integer, optional

Rather than count values, group them into half-open bins, a convenience for pd.cut, only works with numeric data.

dropna : boolean, default True

Don’t include counts of NaN.

Returns:

Series

舉例如下:

import pandas as pd
index = pd.Index([3, 1, 2, 3, 4, np.nan])
index.value_counts()
?
"""
輸出為:
3.0 ? ?2
4.0 ? ?1
2.0 ? ?1
1.0 ? ?1
dtype: int64
"""

如果 normalize 為 True的話,統(tǒng)計(jì)的結(jié)果會(huì)相加 = 1:

import pandas as pd
s = pd.Series([3, 1, 2, 3, 4, np.nan])
s.value_counts(normalize=True)
?
"""
輸出為:
3.0 ? ?0.4
4.0 ? ?0.2
2.0 ? ?0.2
1.0 ? ?0.2
dtype: float64
"""

2.  Series.count(self, level=None)

返回非空值的數(shù)量。若是在 CSV 文件中可用來(lái)統(tǒng)計(jì)行數(shù),如:

import pandas as pd
file = pd.read_csv('test.csv')
print(file['A'].count())
# 此時(shí)輸出的即是 A 列的行數(shù)

參數(shù)含義如下: 

Parameters:

level : int or level name, default None

If the axis is a MultiIndex (hierarchical), count along a particular level, collapsing into a smaller Series.

Returns:

int or Series (if level specified)

Number of non-null values in the Series.

舉例如下:

import pands as pd
s = pd.Series([0.0, 1.0, np.nan])
s.count()
# 此時(shí)輸出為 2

這就是兩者的區(qū)別和各自的用途。

以上為個(gè)人經(jīng)驗(yàn),希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。

相關(guān)文章

  • Python獲取郵件地址的方法

    Python獲取郵件地址的方法

    這篇文章主要介紹了Python獲取郵件地址的方法,通過(guò)自定義函數(shù)分析提取字符串中郵件地址的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-07-07
  • Python寫出新冠狀病毒確診人數(shù)地圖的方法

    Python寫出新冠狀病毒確診人數(shù)地圖的方法

    在本篇文章里小編給大家分享的是關(guān)于Python做新冠狀病毒確診人數(shù)地圖的詳解內(nèi)容,需要的朋友們可以學(xué)習(xí)下。
    2020-02-02
  • python淘寶搶購(gòu)腳本程序?qū)崿F(xiàn)

    python淘寶搶購(gòu)腳本程序?qū)崿F(xiàn)

    大家好,本篇文章主要講的是python淘寶搶購(gòu)腳本程序?qū)崿F(xiàn),感興趣的同學(xué)趕快來(lái)看一看吧,對(duì)你有幫助的話記得收藏一下
    2022-02-02
  • Python實(shí)現(xiàn)統(tǒng)計(jì)代碼行的方法分析

    Python實(shí)現(xiàn)統(tǒng)計(jì)代碼行的方法分析

    這篇文章主要介紹了Python實(shí)現(xiàn)統(tǒng)計(jì)代碼行的方法,結(jié)合實(shí)例形式分析了Python針對(duì)代碼行數(shù)的計(jì)算實(shí)現(xiàn)步驟與操作技巧,需要的朋友可以參考下
    2017-07-07
  • python處理“&#”開(kāi)頭加數(shù)字的html字符方法

    python處理“&#”開(kāi)頭加數(shù)字的html字符方法

    在本篇文章里小編給大家整理了關(guān)于python如何處理“&#”開(kāi)頭加數(shù)字的html字符的相關(guān)知識(shí)點(diǎn)總結(jié),有興趣的朋友們學(xué)習(xí)下。
    2019-06-06
  • Python Celery多隊(duì)列配置代碼實(shí)例

    Python Celery多隊(duì)列配置代碼實(shí)例

    這篇文章主要介紹了Python Celery多隊(duì)列配置代碼實(shí)例,文中通過(guò)示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下
    2019-11-11
  • Python內(nèi)存讀寫操作示例

    Python內(nèi)存讀寫操作示例

    這篇文章主要介紹了Python內(nèi)存讀寫操作,結(jié)合實(shí)例形式分析了Python常見(jiàn)內(nèi)存讀寫操作使用方法及相關(guān)注意事項(xiàng),需要的朋友可以參考下
    2018-07-07
  • YOLOv5部署到web端詳細(xì)過(guò)程(flask+js簡(jiǎn)單易懂)

    YOLOv5部署到web端詳細(xì)過(guò)程(flask+js簡(jiǎn)單易懂)

    YOLOv5是一個(gè)目標(biāo)檢測(cè)模型,Flask是一個(gè)Python的Web框架,下面這篇文章主要給大家介紹了關(guān)于YOLOv5部署到web端(flask+js簡(jiǎn)單易懂)的相關(guān)資料,文中通過(guò)實(shí)例代碼介紹的非常詳細(xì),需要的朋友可以參考下
    2023-04-04
  • 在Python中利用Into包整潔地進(jìn)行數(shù)據(jù)遷移的教程

    在Python中利用Into包整潔地進(jìn)行數(shù)據(jù)遷移的教程

    這篇文章主要介紹了在Python中如何利用Into包整潔地進(jìn)行數(shù)據(jù)遷移,在數(shù)據(jù)格式的任意兩個(gè)格式之間高效地遷移數(shù)據(jù),需要的朋友可以參考下
    2015-03-03
  • python jinja2模板的使用示例

    python jinja2模板的使用示例

    這篇文章主要介紹了python jinja2模板的使用示例,幫助大家更好的理解和學(xué)習(xí)使用python,感興趣的朋友可以了解下
    2021-03-03

最新評(píng)論