Series
一划栓、何為Series茧彤?
- Series是一種類似于一維數(shù)組的對(duì)象常侦,它由一組數(shù)據(jù)(各種Numpy數(shù)據(jù)類型)以及一組與之相關(guān)的數(shù)據(jù)標(biāo)簽(即索引)組成
二洋机、如何創(chuàng)建Series?
import pandas as pd
obj = pd.Series([4,7,-5,3])
obj2 = pd.Series([4,7,-5,3],index=['d','b','a','c'])
obj3 = pd.Series({'zhang':35, 'li':67, 'wang':78})
obj4 = pd.Series({'zhang':35, 'li':67, 'wang':78},index=['li','zhao','wang'])
-
obj4
:索引匹配并生成新的Series坠宴;近似于從Python字典中生成由某些特定鍵組成的子字典;可用于查找
三绷旗、Series的屬性
-
values
屬性:obj.values
-
index
屬性:obj.index
-
name
屬性:obj.name
,obj.index.name
四喜鼓、Series的選取
- 基于索引選取:
obj2.loc['a']
(推薦)衔肢、obj2['a']
庄岖、obj2.loc[['a','d','b']]
(推薦)、obj2[['a','d','b']]
膀懈、obj2.loc['d':'a']
(推薦)顿锰、obj2['d':'a']
- 基于位置選取:
obj2.iloc[2]
(推薦)、obj2[2]
硼控、obj2.iloc[[2,0,1]]
(推薦)刘陶、obj2[[2,0,1]]
、obj2.iloc[:2]
(推薦)牢撼、obj2[:2]
- 基于內(nèi)容選瘸赘簟:
obj2[obj2 < 5]
五、Series的運(yùn)算
- Series在算術(shù)計(jì)算時(shí)會(huì)根據(jù)索引自動(dòng)對(duì)齊熏版;可以忽略數(shù)據(jù)順序的影響
六纷责、Series檢測(cè)缺失值的實(shí)例方法
obj4.isnull()
obj4.notnull()
七、Series賦值就地修改索引
obj.index = ['zhang','li','wang','zhao']