python中drop用法 Python的pandas中,drop_duplicates函數(shù)怎么根據(jù)索引來去重?
Python的pandas中,drop_duplicates函數(shù)怎么根據(jù)索引來去重?今天,我想去重復(fù)熊貓的臺詞。很長一段時(shí)間后,我找到了相關(guān)的函數(shù)讓我們先看一個(gè)小例子[Python]查看純拷貝來自pa
Python的pandas中,drop_duplicates函數(shù)怎么根據(jù)索引來去重?
今天,我想去重復(fù)熊貓的臺詞。很長一段時(shí)間后,我找到了相關(guān)的函數(shù)
讓我們先看一個(gè)小例子
[Python]查看純拷貝
來自pandas import series,dataframe
data=dataframe({“K”:[1,1,2,2] })
打印數(shù)據(jù)
isduplicated=數(shù)據(jù)。重復(fù)()
打印重復(fù)
打印類型(重復(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è)方法將判斷所有列,您還可以指定一些列來判斷重復(fù)項(xiàng)。
例如,您要對名為K2的列進(jìn)行重復(fù)數(shù)據(jù)消除data.drop重復(fù)([“k2”])