pandas中的Series和DataFrame-創(chuàng)新互聯(lián)

1.Series介紹及創(chuàng)建

站在用戶的角度思考問題,與客戶深入溝通,找到洪澤網(wǎng)站設(shè)計與洪澤網(wǎng)站推廣的解決方案,憑借多年的經(jīng)驗,讓設(shè)計與互聯(lián)網(wǎng)技術(shù)結(jié)合,創(chuàng)造個性化、用戶體驗好的作品,建站類型包括:做網(wǎng)站、網(wǎng)站制作、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣、域名注冊雅安服務(wù)器托管、企業(yè)郵箱。業(yè)務(wù)覆蓋洪澤地區(qū)。

Series是一種類似與一維數(shù)組的對象,由下面兩個部分組成:

values:一組數(shù)據(jù)(ndarray類型)

index:相關(guān)的數(shù)據(jù)索引標簽

創(chuàng)建Series的兩種方式:

第一種:由列表或numpy數(shù)組創(chuàng)建:

s1 =Series([11,22,33,44,55],index=['a1','b1','c1','d1','e1'],name='Hello world')

print(s1)

運行結(jié)果:

a1 11

b1 22

c1 33

d1 44

e1 55

Name: Hello world, dtype: int64

a1 = np.array([11,22,33,44,55])

s2 = Series(a1,index=['a1','b1','c1','d1','e1'],name='hello series')

print(s2)

運行結(jié)果:

a1 11

b1 22

c1 33

d1 44

e1 55

Name: hello series, dtype: int32

第二種:由字典創(chuàng)建,不存在index參數(shù)設(shè)置,但是依然存在默認索引(數(shù)據(jù)源必須為一維數(shù)據(jù))

dict = {'hello':12,'series':30}

s3 = Series(data=dict)

print(s3)

運行結(jié)果:

hello 12

series 30

dtype: int64

2.DataFrame的介紹及創(chuàng)建

DataFrame具有標記軸(行和列)的二維大小可變,可能異構(gòu)的表格數(shù)據(jù)結(jié)構(gòu)

算術(shù)運算在行標簽和列標簽上對齊

可以被認為是Series對象的類似dict的容器

是pandas的主要數(shù)據(jù)結(jié)構(gòu)

創(chuàng)建DataFrame的4種方式:

1.使用字典創(chuàng)建DataFarme

dicts = {"tag1": [90, 22, 66],'tag2': [12, 33, 66]}

d1 = DataFrame(data=dicts, index=['a', 'b', 'c'])

print(d1)

運行結(jié)果:

tag1 tag2

a 90 12

b 22 33

c 66 66

2.使用ndarray創(chuàng)建DataFrame

d2 = DataFrame(data=np.random.randint(0,100,size=(3,6)),index=["one","two","three"],columns=["a","b","c","d","e","f"])

print(d2)

運行結(jié)果:無錫人流醫(yī)院 http://xmobile.wxbhnk120.com/

a b c d e f

one 62 74 51 29 98 18

two 16 16 44 3 64 72

three 42 94 46 60 34 59

3.隱式構(gòu)造

最常見的方法是給DataFrame構(gòu)造函數(shù)的index或者columns參數(shù)傳遞兩個或更多的數(shù)組(如下另個列的標簽數(shù)組)

d3 = DataFrame(data=np.random.randint(0, 100, size=(2, 4)), index=['x', 'y'], columns=[['a', 'b', 'c', 'd'], ['q1', 'q2', 'q3', 'q4']])

print(d3)

運行結(jié)果:

a b c d

q1 q2 q3 q4

x 47 26 11 8

y 40 76 18 9

4.顯示構(gòu)造

使用pd.MultiIndex.from_arrays數(shù)組方式

創(chuàng)建了一個索引對象,該索引對象為二層索引

indexObj = pd.MultiIndex.from_arrays([['q1', 'q2', 'q3', 'q1'], ['a', 'b', 'c', 'd']])

d4 = DataFrame(data=np.random.randint(0, 100, size=(2, 4)), index=['x', 'y'], columns=indexObj)

print(d4)

運行結(jié)果:

q1 q2 q3 q1

a b c d

x 85 72 43 4

y 8 43 55 68

另外有需要云服務(wù)器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務(wù)器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務(wù)器、裸金屬服務(wù)器、高防服務(wù)器、香港服務(wù)器、美國服務(wù)器、虛擬主機、免備案服務(wù)器”等云主機租用服務(wù)以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務(wù)可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應(yīng)用場景需求。

當(dāng)前文章:pandas中的Series和DataFrame-創(chuàng)新互聯(lián)
本文來源:http://muchs.cn/article2/dppeoc.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供網(wǎng)站改版ChatGPT、品牌網(wǎng)站建設(shè)、標簽優(yōu)化電子商務(wù)、App開發(fā)

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

成都seo排名網(wǎng)站優(yōu)化