Pandas數據結構中Series屬性詳解
Series屬性
Series屬性列表
| 屬性 | 說明 |
|---|---|
| Series.index | 系列的索引(軸標簽) |
| Series.array | 系列或索引的數據 |
| Series.values | 系列的數據,返回ndarray |
| Series.dtype | 返回基礎數據的數據類型 |
| Series.shape | 返回基礎數據形狀的元組 |
| Series.nbytes | 返回基礎數據占的字節(jié)數 |
| Series.ndim | 基礎數據的維數,永遠是1 |
| Series.size | 返回基礎數據中元素的個數 |
| Series.T | 返回轉置,永遠為Series自己 |
| Series.memory_usage([index, deep]) | 返回系列的內存使用情況 |
| Series.hasnans | 如果有任何 NaN,則返回 True |
| Series.empty | 指示 Series是否為空 |
| Series.dtypes | 返回基礎數據的數據類型 |
| Series.name | 返回系列的名稱 |
| Series.flags | 獲取與此 pandas 對象關聯的屬性 |
| Series.set_flags(*[,copy,…]) | 返回帶有更新標志的新對象 |
Series屬性詳解
由于Series是一個可以自定義行索引的一維數據,所以Series的屬性大部分都是ndarray的屬性,在ndarray屬性的基礎上有了新的擴展,其中比較重要的是index,values等。詳細介紹示例如下:(建議看不懂說明的可以直接看示例,示例更容易懂)
>>> 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 # 數組 <PandasArray> # 返回的數據類型為PandasArray [10, 11, 12, 13, 14, 15] Length: 6, dtype: int16
Series.values
>>> ser01.values # 數據 array([10, 11, 12, 13, 14, 15], dtype=int16) # 返回值為ndarray
Series.dtype
>>> ser01.dtype # 元素的數據類型
dtype('int16')Series.shape
>>> ser01.shape # 形狀 (6,)
Series.nbytes
>>> ser01.nbytes # 占用多少字節(jié) 12
Series.ndim
>>> ser01.ndim # 維度,維數,軸數,秩 1 # 永遠是1,Series是一維數組
Series.T
>>> ser01.T # 轉置,是它本身 a 10 b 11 c 12 d 13 e 14 f 15 Name: class02, dtype: int16
Series.memory_usage([index, deep])
>>> ser01.memory_usage() # 內存使用量 232
Series.hasnans
>>> ser01.hasnans # 是否有空值 False
Series.empty
>>> ser01.empty # 是否為空 False
Series.dtypes
>>> ser01.dtypes # 元素數據類型,同dtype
dtype('int16')Series.name
>>> ser01.name # ser01的名字 'class02'
Series.flags
>>> ser01.flags # 此 pandas 對象關聯的屬性 <Flags(allows_duplicate_labels=True)>
Series.set_flags(*[,copy,…])
>>> ser01.set_flags() # 返回帶有更新標志的新對象 a 10 b 11 c 12 d 13 e 14 f 15 Name: class02, dtype: int32
需要掌握屬性的名稱和意義,還有屬性的返回值屬于哪種數據類型,是一個什么值。在數據分析或者可視化中會使用Series屬性的返回值作為其他函數的參數使用,因此必須熟練掌握。
到此這篇關于Pandas數據結構中Series屬性詳解的文章就介紹到這了,更多相關Pandas Series屬性內容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
用PyQt進行Python圖形界面的程序的開發(fā)的入門指引
這篇文章主要介紹了用PyQt進行Python圖形界面的程序的開發(fā)的入門指引,來自于IBM官方網站技術文檔,需要的朋友可以參考下2015-04-04
python使用 request 發(fā)送表單數據操作示例
這篇文章主要介紹了python使用 request 發(fā)送表單數據操作,結合實例形式分析了Python基于requests模塊的表單數據發(fā)送操作相關實現技巧,需要的朋友可以參考下2019-09-09

