Pandas數(shù)據(jù)結(jié)構(gòu)中Series屬性詳解
Series屬性
Series屬性列表
屬性 | 說明 |
---|---|
Series.index | 系列的索引(軸標(biāo)簽) |
Series.array | 系列或索引的數(shù)據(jù) |
Series.values | 系列的數(shù)據(jù),返回ndarray |
Series.dtype | 返回基礎(chǔ)數(shù)據(jù)的數(shù)據(jù)類型 |
Series.shape | 返回基礎(chǔ)數(shù)據(jù)形狀的元組 |
Series.nbytes | 返回基礎(chǔ)數(shù)據(jù)占的字節(jié)數(shù) |
Series.ndim | 基礎(chǔ)數(shù)據(jù)的維數(shù),永遠(yuǎn)是1 |
Series.size | 返回基礎(chǔ)數(shù)據(jù)中元素的個數(shù) |
Series.T | 返回轉(zhuǎn)置,永遠(yuǎn)為Series自己 |
Series.memory_usage([index, deep]) | 返回系列的內(nèi)存使用情況 |
Series.hasnans | 如果有任何 NaN,則返回 True |
Series.empty | 指示 Series是否為空 |
Series.dtypes | 返回基礎(chǔ)數(shù)據(jù)的數(shù)據(jù)類型 |
Series.name | 返回系列的名稱 |
Series.flags | 獲取與此 pandas 對象關(guān)聯(lián)的屬性 |
Series.set_flags(*[,copy,…]) | 返回帶有更新標(biāo)志的新對象 |
Series屬性詳解
由于Series是一個可以自定義行索引的一維數(shù)據(jù),所以Series的屬性大部分都是ndarray的屬性,在ndarray屬性的基礎(chǔ)上有了新的擴(kuò)展,其中比較重要的是index,values等。詳細(xì)介紹示例如下:(建議看不懂說明的可以直接看示例,示例更容易懂)
>>> import numpy as np >>> import pandas as pd # 創(chuàng)建ser01 >>> arr01 = np.arange(10, 16) >>> ser01 = pd.Series(data=arr01, index=['a','b','c','d','e','f'], dtype='int16', name='class02') >>> ser01 a 10 b 11 c 12 d 13 e 14 f 15 Name: class02, dtype: int16
屬性:
Series.index
>>> ser01.index # 索引 Index(['a', 'b', 'c', 'd', 'e', 'f'], dtype='object')
Series.array
>>> ser01.array # 數(shù)組 <PandasArray> # 返回的數(shù)據(jù)類型為PandasArray [10, 11, 12, 13, 14, 15] Length: 6, dtype: int16
Series.values
>>> ser01.values # 數(shù)據(jù) array([10, 11, 12, 13, 14, 15], dtype=int16) # 返回值為ndarray
Series.dtype
>>> ser01.dtype # 元素的數(shù)據(jù)類型 dtype('int16')
Series.shape
>>> ser01.shape # 形狀 (6,)
Series.nbytes
>>> ser01.nbytes # 占用多少字節(jié) 12
Series.ndim
>>> ser01.ndim # 維度,維數(shù),軸數(shù),秩 1 # 永遠(yuǎn)是1,Series是一維數(shù)組
Series.T
>>> ser01.T # 轉(zhuǎn)置,是它本身 a 10 b 11 c 12 d 13 e 14 f 15 Name: class02, dtype: int16
Series.memory_usage([index, deep])
>>> ser01.memory_usage() # 內(nèi)存使用量 232
Series.hasnans
>>> ser01.hasnans # 是否有空值 False
Series.empty
>>> ser01.empty # 是否為空 False
Series.dtypes
>>> ser01.dtypes # 元素數(shù)據(jù)類型,同dtype dtype('int16')
Series.name
>>> ser01.name # ser01的名字 'class02'
Series.flags
>>> ser01.flags # 此 pandas 對象關(guān)聯(lián)的屬性 <Flags(allows_duplicate_labels=True)>
Series.set_flags(*[,copy,…])
>>> ser01.set_flags() # 返回帶有更新標(biāo)志的新對象 a 10 b 11 c 12 d 13 e 14 f 15 Name: class02, dtype: int32
需要掌握屬性的名稱和意義,還有屬性的返回值屬于哪種數(shù)據(jù)類型,是一個什么值。在數(shù)據(jù)分析或者可視化中會使用Series屬性的返回值作為其他函數(shù)的參數(shù)使用,因此必須熟練掌握。
到此這篇關(guān)于Pandas數(shù)據(jù)結(jié)構(gòu)中Series屬性詳解的文章就介紹到這了,更多相關(guān)Pandas Series屬性內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
Python中基本數(shù)據(jù)類型和常用語法歸納分享
這篇文章主要為大家整理記錄了Python中基本數(shù)據(jù)類型和常用語法的使用,文中的示例代碼講解詳細(xì),感興趣的小伙伴可以跟隨小編一起了解一下2023-04-04用PyQt進(jìn)行Python圖形界面的程序的開發(fā)的入門指引
這篇文章主要介紹了用PyQt進(jìn)行Python圖形界面的程序的開發(fā)的入門指引,來自于IBM官方網(wǎng)站技術(shù)文檔,需要的朋友可以參考下2015-04-04python處理帶有時區(qū)的日期和時間數(shù)據(jù)
這篇文章主要為大家詳細(xì)介紹了如何在Python中使用pytz庫處理時區(qū)信息,包括獲取當(dāng)前UTC時間,轉(zhuǎn)換為特定時區(qū)等,有需要的小伙伴可以參考一下2025-04-04python利用thrift服務(wù)讀取hbase數(shù)據(jù)的方法
今天小編就為大家分享一篇python利用thrift服務(wù)讀取hbase數(shù)據(jù)的方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧2018-12-12python使用 request 發(fā)送表單數(shù)據(jù)操作示例
這篇文章主要介紹了python使用 request 發(fā)送表單數(shù)據(jù)操作,結(jié)合實例形式分析了Python基于requests模塊的表單數(shù)據(jù)發(fā)送操作相關(guān)實現(xiàn)技巧,需要的朋友可以參考下2019-09-09