1. 程式人生 > >pandas 學習彙總9 - Series系列,DataFrame資料幀 屬性( tcy)

pandas 學習彙總9 - Series系列,DataFrame資料幀 屬性( tcy)

Series-屬性  2018/11/8  2018/12/6

序列: 

# 可以把Series看成有序字典;均勻資料;尺寸資料均可變
s=pd.Series(data=np.arange(10,15),index=pd.Index(list('abcde')),dtype=np.float, name='Series-1')

屬性簡表:

屬性 說明
s.at[] 訪問行/列標籤對的單個值。
s.axes 返回行軸標籤列表 [Index(['a', 'b', 'c', 'd', 'e'], dtype='object')]
s.dtype 返回基礎資料的dtype物件dtype('float64')
s.dtypes 返回基礎資料的dtype物件dtype('float64')
s.empty 系列為空返回 True
s.flags  -
s.ftype 如資料稀疏則返回 'float64:dense'
s.ftypes 如資料稀疏則返回 'float64:dense'
s.hasnans
如有nans返回True False
s.iat[] 按整數位置訪問行/列對的單個值。
s.iloc[] 純粹基於整數位置的索引,用於按位置選擇。
s.imag array([0., 0., 0., 0., 0.])
s.imag array([0., 0., 0., 0., 0.])
s.index 系列索引(軸標籤)Index(['a', 'b', 'c', 'd', 'e'], dtype='object')
s.is_monotonic
如序列中值遞增返回True
s.is_monotonic_decreasing 如序列中值遞減返回True
s.is_monotonic_increasing 如序列中值遞增返回True
s.is_unique 如果物件中的所有值都是唯一返回True
s.itemsize 返回基礎資料項的dtype的大小 8
s.ix[] 主要基於標籤位置的索引器,具有整數位置回退。
s.loc[] 通過標籤或布林陣列訪問一組行和列。
s.memory_usage() 返回Series的記憶體使用情況240
s.nbytes 返回基礎資料位元組數 40
s.ndim 返回基礎資料維數 1
s.real array([10., 11., 12., 13., 14.])
s.shape 返回資料形狀元組 (5,)
s.size 返回資料元素數量 5
s.strides 返回資料步幅 (8,)
s.values 返回系列值 dtype array([10., 11., 12., 13., 14.])

例項: 

s.flags
'''
C_CONTIGUOUS : True
F_CONTIGUOUS : True
OWNDATA : True
WRITEABLE : True
ALIGNED : True
WRITEBACKIFCOPY : False
UPDATEIFCOPY : False
''' 

 DataFrame-屬性   2018/12/7  

屬性: 

# 所有Pandas資料結構是值可變的(數值大小可更改)
# DataFrame索引(行)和列(不同型別) ;大小可變 可對行和列執行算術運算

data = {'Name':pd.Series(['Tom','Jim','Bob']),'Age':pd.Series([25,26,25]),
'sex':pd.Series([0,1,0],dtype=bool)}
df=pd.DataFrame(data)  

簡表:

屬性 說明
df.at[] 訪問行/列標籤對的單個值
df.axes 行軸標籤列表 [RangeIndex(start=0, stop=3, step=1),
 - Index(['Name', 'Age', 'sex'], dtype='object')]
df.columns 列標籤#Index(['Name', 'Age', 'sex'], dtype='object')
df.dtypes 資料型別 #Name object Age int64 sex bool dtype: object
df.empty 物件為空返回True 
df.ftypes 返回資料幀中的ftypes(稀疏/密集和dtype的指示)
df.iat[] 按整數位置訪問行/列對的單個值
df.iloc[] 整數位置索引,用於按位置選擇
df.index 索引行標籤  #RangeIndex(start=0, stop=3, step=1)
df.ix[] 主要基於標籤位置的索引器,具有整數位置回退
df.loc[] 通過標籤或布林陣列訪問一組行和列
df.memory_usage() 記憶體使用情況#Index 80 Name 24 Age 24 sex 3 dtype: int64
df.ndim 基礎資料維數 2
df.shape 資料形狀元組 (3, 3)
df.size 資料元素數量 9
df.style 返回Styler物件的屬性# pandas.io.formats.style.Styler
df.T 轉置
df.values 返回資料幀的ndarray #array([['Tom', ...],…,  dtype=object)

 

例項:

df.T
# 0 1 2
# Name Tom Jim Bob
# Age 25 26 25
# sex False True False

df.ftypes
# Name object:dense
# Age int64:dense
# sex bool:dense
# dtype: object