pandas multiindex 如何刪除pythonpandas.DataFrame的多重index?
如何刪除pythonpandas.DataFrame的多重index? 測(cè)向復(fù)位索引()有關(guān)詳細(xì)用法,請(qǐng)參閱文檔https://pandas.pydata.org/pandas-docs/stable
如何刪除pythonpandas.DataFrame的多重index?
測(cè)向復(fù)位索引()
有關(guān)詳細(xì)用法,請(qǐng)參閱文檔https://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.reset索引.html
Python的pandas數(shù)組如何得到索引值,如圖,我要得到ohio的索引值,應(yīng)該怎樣做?
今天,我想去重復(fù)的熊貓行。很長(zhǎng)一段時(shí)間后,我找到了相關(guān)的函數(shù)
讓我們先看一個(gè)小例子
[Python]查看純拷貝
來(lái)自pandas import series,dataframe
data=dataframe({“K”:[1,1,2,2] })
打印數(shù)據(jù)
isduplicated=數(shù)據(jù)。重復(fù)()
打印重復(fù)
打印類(lèi)型(重復(fù))
數(shù)據(jù)=data.drop復(fù)制()
打印數(shù)據(jù)
執(zhí)行結(jié)果是:
[Python]查看純拷貝
k
0 1
1 1
2 2
3 2
[Python]查看純拷貝
0 false
1true
2 false
3 true
[Python]查看純拷貝
k
0 1
2
dataframe的duplicated方法返回一個(gè)布爾序列,指示每行是否重復(fù)。
And drop_u2;replications方法,用于返回刪除重復(fù)行的數(shù)據(jù)幀
這兩個(gè)方法將判斷所有列,您還可以指定一些列來(lái)判斷重復(fù)項(xiàng)。
例如,您要對(duì)名為K2的列進(jìn)行重復(fù)數(shù)據(jù)消除data.drop重復(fù)([“K2”
如何用pandas實(shí)現(xiàn)選取特定索引的行?
共享在panda中選擇特定索引行的方法,希望對(duì)您有所幫助:
>>>>導(dǎo)入numpy作為NP
>>導(dǎo)入panda作為PD
>>>索引=np.數(shù)組([2,4,6,8,10])
>>>>數(shù)據(jù)=np.數(shù)組([3,5,7,9,11])
>>>>數(shù)據(jù)=pd.數(shù)據(jù)幀({“num”:data},index=index)
>>>打?。〝?shù)據(jù))
num
2 3
4 5
67
8 9
10 11
>>>選擇索引=索引[索引> 5
]>>>打?。ㄟx擇索引)
[6 8 10
]>>>數(shù)據(jù)[“num”]。loc[選擇索引
]6 7
8 9
10 11
名稱(chēng):num,數(shù)據(jù)類(lèi)型:int32
>>
請(qǐng)注意不能使用iloc。Iloc以數(shù)組的形式訪(fǎng)問(wèn)序列,下標(biāo)從0:]>>>> data[“num”]開(kāi)始。Iloc[2:5
]6 7
8 9
10 11
名稱(chēng):num,數(shù)據(jù)類(lèi)型:int32
>>>>數(shù)據(jù)[“num”]。Iloc[[2,3,4
6 7
8 9
10 11
名稱(chēng):num,數(shù)據(jù)類(lèi)型:int32
>>>;數(shù)據(jù)[“num”]
>>>
您可以試一試