亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

Python數(shù)據(jù)處理之pd.Series()函數(shù)的基本使用

 更新時間:2022年06月22日 11:53:16   作者:流年里不舍的執(zhí)著  
Series是帶標簽的一維數(shù)組,可存儲整數(shù)、浮點數(shù)、字符串、Python 對象等類型的數(shù)據(jù),軸標簽統(tǒng)稱為索引,下面這篇文章主要給大家介紹了關于Python數(shù)據(jù)處理之pd.Series()函數(shù)的基本使用,需要的朋友可以參考下

1.Series介紹

Pandas模塊的數(shù)據(jù)結(jié)構(gòu)主要有兩種:1.Series 2.DataFrame

Series 是一維數(shù)組,基于Numpy的ndarray 結(jié)構(gòu)

Series([data, index, dtype, name, copy, …])    
# One-dimensional ndarray with axis labels (including time series).

2.Series創(chuàng)建

import Pandas as pd 
import numpy as np

1.pd.Series([list],index=[list])

參數(shù)為list ,index為可選參數(shù),若不填寫則默認為index從0開始

obj = pd.Series([4, 7, -5, 3, 7, np.nan])
obj

輸出結(jié)果為:

0    4.0
1    7.0
2   -5.0
3    3.0
4    7.0
5    NaN
dtype: float64

2.pd.Series(np.arange())

arr = np.arange(6)
s = pd.Series(arr)
s

輸出結(jié)果為:

0    0
1    1
2    2
3    3
4    4
5    5
dtype: int32

pd.Series({dict})
d = {'a':10,'b':20,'c':30,'d':40,'e':50}
s = pd.Series(d)
s

輸出結(jié)果為:

a    10
b    20
c    30
d    40
e    50
dtype: int64

可以通過DataFrame中某一行或者某一列創(chuàng)建序列

3 Series基本屬性

  • Series.values:Return Series as ndarray or ndarray-like depending on the dtype
obj.values
# array([ 4.,  7., -5.,  3.,  7., nan])
  • Series.index:The index (axis labels) of the Series.
obj.index
# RangeIndex(start=0, stop=6, step=1)
  • Series.name:Return name of the Series.

4 索引

  • Series.loc:Access a group of rows and columns by label(s) or a boolean array.
  • Series.iloc:Purely integer-location based indexing for selection by position.

5 計算、描述性統(tǒng)計

 Series.value_counts:Return a Series containing counts of unique values.

index = ['Bob', 'Steve', 'Jeff', 'Ryan', 'Jeff', 'Ryan'] 
obj = pd.Series([4, 7, -5, 3, 7, np.nan],index = index)
obj.value_counts()

輸出結(jié)果為:

 7.0    2
 3.0    1
-5.0    1
 4.0    1
dtype: int64

6 排序

Series.sort_values

Series.sort_values(self, axis=0, ascending=True, inplace=False, kind='quicksort', na_position='last')

Parameters:

ParametersDescription
axis{0 or ‘index’}, default 0,Axis to direct sorting. The value ‘index’ is accepted for compatibility with DataFrame.sort_values.
ascendinbool, default True,If True, sort values in ascending order, otherwise descending.
inplacebool, default FalseIf True, perform operation in-place.
kind{‘quicksort’, ‘mergesort’ or ‘heapsort’}, default ‘quicksort’Choice of sorting algorithm. See also numpy.sort() for more information. ‘mergesort’ is the only stable algorithm.
na_position{‘first’ or ‘last’}, default ‘last’,Argument ‘first’ puts NaNs at the beginning, ‘last’ puts NaNs at the end.

Returns:

Series:Series ordered by values.

obj.sort_values()

輸出結(jié)果為:

Jeff    -5.0
Ryan     3.0
Bob      4.0
Steve    7.0
Jeff     7.0
Ryan     NaN
dtype: float64

  • Series.rank
Series.rank(self, axis=0, method='average', numeric_only=None, na_option='keep', ascending=True, pct=False)[source]

Parameters:

ParametersDescription
axis{0 or ‘index’, 1 or ‘columns’}, default 0Index to direct ranking.
method{‘average’, ‘min’, ‘max’, ‘first’, ‘dense’}, default ‘average’How to rank the group of records that have the same value (i.e. ties): average, average rank of the group; min: lowest rank in the group; max: highest rank in the group; first: ranks assigned in order they appear in the array; dense: like ‘min’, but rank always increases by 1,between groups
numeric_onlybool, optional,For DataFrame objects, rank only numeric columns if set to True.
na_option{‘keep’, ‘top’, ‘bottom’}, default ‘keep’, How to rank NaN values:;keep: assign NaN rank to NaN values; top: assign smallest rank to NaN values if ascending; bottom: assign highest rank to NaN values if ascending
ascendingbool, default True Whether or not the elements should be ranked in ascending order.
pctbool, default False Whether or not to display the returned rankings in percentile form.

Returns:

same type as caller :Return a Series or DataFrame with data ranks as values.

# obj.rank()            #從大到小排,NaN還是NaN
obj.rank(method='dense')  
# obj.rank(method='min')
# obj.rank(method='max')
# obj.rank(method='first')
# obj.rank(method='dense')

輸出結(jié)果為:

Bob      3.0
Steve    4.0
Jeff     1.0
Ryan     2.0
Jeff     4.0
Ryan     NaN
dtype: float64

總結(jié)

到此這篇關于Python數(shù)據(jù)處理之pd.Series()函數(shù)的基本使用的文章就介紹到這了,更多相關Python pd.Series()函數(shù)內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:

相關文章

  • python3中dict(字典)的使用方法示例

    python3中dict(字典)的使用方法示例

    這篇文章主要介紹了python3中dict(字典)的使用方法,文中給出了詳細的功能列舉,對大家具有一定的參考價值,需要的朋友們下面來一起看看吧。
    2017-03-03
  • python中利用await關鍵字如何等待Future對象完成詳解

    python中利用await關鍵字如何等待Future對象完成詳解

    為了簡化并更好地標識異步IO,從Python 3.5開始引入了新的語法async和await,可以讓coroutine的代碼更簡潔易讀。下面這篇文章主要給大家介紹了關于python中利用await關鍵字如何等待Future對象完成的相關資料,需要的朋友可以參考下。
    2017-09-09
  • Django Admin實現(xiàn)三級聯(lián)動的示例代碼(省市區(qū))

    Django Admin實現(xiàn)三級聯(lián)動的示例代碼(省市區(qū))

    多級菜單在很多上面都有應用,這篇文章主要介紹了Django Admin實現(xiàn)三級聯(lián)動(省市區(qū)),小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2018-06-06
  • Python包裝異常處理方法

    Python包裝異常處理方法

    這篇文章主要介紹了Python包裝異常處理方法,相比java,python的異常和java中不同,python主要是防止程序異常被中止。一旦被catch后它還行往下執(zhí)行,本文就分享python相關的異常處理方法,需要的小伙伴可以參考一下
    2022-06-06
  • tensorflow查看ckpt各節(jié)點名稱實例

    tensorflow查看ckpt各節(jié)點名稱實例

    今天小編就為大家分享一篇tensorflow查看ckpt各節(jié)點名稱實例,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-01-01
  • Python使用oslo.vmware管理ESXI虛擬機的示例參考

    Python使用oslo.vmware管理ESXI虛擬機的示例參考

    oslo.vmware是OpenStack通用框架中的一部分,主要用于實現(xiàn)對虛擬機的管理任務,借助oslo.vmware模塊我們可以管理Vmware ESXI集群環(huán)境。
    2021-06-06
  • python之生成多層json結(jié)構(gòu)的實現(xiàn)

    python之生成多層json結(jié)構(gòu)的實現(xiàn)

    今天小編就為大家分享一篇python之生成多層json結(jié)構(gòu)的實現(xiàn),具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-02-02
  • Python3.7 dataclass使用指南小結(jié)

    Python3.7 dataclass使用指南小結(jié)

    本文將帶你走進python3.7的新特性dataclass,通過本文你將學會dataclass的使用并避免踏入某些陷阱。小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2019-02-02
  • 解決python?pip安裝第三方模塊報錯:error:legacy-install-failure

    解決python?pip安裝第三方模塊報錯:error:legacy-install-failure

    pip是python的第三方庫管理器,可以根據(jù)所開發(fā)項目的需要,使用pip相關命令安裝不同庫,下面這篇文章主要給大家介紹了關于解決python?pip安裝第三方模塊報錯:error:?legacy?-?install?-?failure的相關資料,需要的朋友可以參考下
    2023-04-04
  • 深入淺析Python 中的sklearn模型選擇

    深入淺析Python 中的sklearn模型選擇

    這篇文章主要介紹了Python sklearn模型選擇的相關知識,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下
    2019-10-10

最新評論