pandas: shape()獲取Dataframe得行數(shù)和列數(shù)
返回列數(shù):
df.shape[1]
返回行數(shù):
df.shape[0] 或者:len(df)
返回形狀,即幾行幾列得數(shù)組
dataframe.shape()
執(zhí)行df.shape會(huì)返回一個(gè)元組,該元組得第一個(gè)元素代表行數(shù),第二個(gè)元素代表列數(shù),這就是這個(gè)數(shù)據(jù)得基本形狀,也是數(shù)據(jù)得大小
import pandas as pd df = pd.DataFrame([['liver','E',89,21,24,64], ['Arry','C',36,37,37,57], ['Ack','A',57,60,18,84], ['Eorge','C',93,96,71,78], ['Oah','D',65,49,61,86] ], columns = ['name','team','Q1','Q2','Q3','Q4']) df.shape# (5, 6)# 共5行6列(索引不算) df.shape[0] # 5df.shape[1] # 6 # Series只有一個(gè)值s = pd.Series(['One','Two','Three'])s.shape # (3,)s.shape[0] # 3
結(jié)果展示
df
s
到此這篇關(guān)于Pandas數(shù)據(jù)形狀df.shape得實(shí)現(xiàn)得內(nèi)容就介紹到這了,更多相關(guān)Pandas df.shape內(nèi)容請(qǐng)搜索之家以前得內(nèi)容或繼續(xù)瀏覽下面得相關(guān)內(nèi)容希望大家以后多多支持之家!
聲明:所有內(nèi)容來(lái)自互聯(lián)網(wǎng)搜索結(jié)果,不保證100%準(zhǔn)確性,僅供參考。如若本站內(nèi)容侵犯了原著者的合法權(quán)益,可聯(lián)系我們進(jìn)行處理。