本文介紹了在 Pandas DataFrame 中刪除重復(fù)索引的最快方法的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
如果我想在數(shù)據(jù)框中刪除重復(fù)的索引,由于顯而易見的原因,以下方法不起作用:
If I want to drop duplicated index in a dataframe the following doesn't work for obvious reasons:
myDF.drop_duplicates(cols=index)
和
myDF.drop_duplicates(cols='index')
查找名為索引"的列
如果我想刪除一個(gè)索引,我必須這樣做:
If I want to drop an index I have to do:
myDF['index'] = myDF.index
myDF= myDF.drop_duplicates(cols='index')
myDF.set_index = myDF['index']
myDF= myDF.drop('index', axis =1)
有沒有更有效的方法?
推薦答案
很簡(jiǎn)單:DF.groupby(DF.index).first()
這篇關(guān)于在 Pandas DataFrame 中刪除重復(fù)索引的最快方法的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!
【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!