濮阳杆衣贸易有限公司

主頁 > 知識庫 > pandas中DataFrame檢測重復(fù)值的實(shí)現(xiàn)

pandas中DataFrame檢測重復(fù)值的實(shí)現(xiàn)

熱門標(biāo)簽:河北防封卡電銷卡 天津電話機(jī)器人公司 應(yīng)電話機(jī)器人打電話違法嗎 電銷機(jī)器人的風(fēng)險(xiǎn) 開封語音外呼系統(tǒng)代理商 開封自動外呼系統(tǒng)怎么收費(fèi) 手機(jī)網(wǎng)頁嵌入地圖標(biāo)注位置 地圖標(biāo)注線上如何操作 400電話辦理哪種

本文詳解如何使用pandas查看dataframe的重復(fù)數(shù)據(jù),判斷是否重復(fù),以及如何去重

DataFrame.duplicated(subset=None, keep='first')

subset:如果你認(rèn)為幾個字段重復(fù),則數(shù)據(jù)重復(fù),就把那幾個字段以列表形式放到subset后面。默認(rèn)是所有字段重復(fù)為重復(fù)數(shù)據(jù)。

keep:

  • 默認(rèn)為'first' ,也就是如果有重復(fù)數(shù)據(jù),則第一條出現(xiàn)的定義為False,后面的重復(fù)數(shù)據(jù)為True。
  • 如果為'last',也就是如果有重復(fù)數(shù)據(jù),則最后一條出現(xiàn)的定義為False,后面的重復(fù)數(shù)據(jù)為True。
  • 如果為False,則所有重復(fù)的為True

下面舉例

df = pd.DataFrame({
    'brand': ['Yum Yum', 'Yum Yum', 'Indomie', 'Indomie', 'Indomie'],
    'style': ['cup', 'cup', 'cup', 'pack', 'pack'],
    'rating': [4, 4, 3.5, 15, 5]
})
df 

# 默認(rèn)為keep="first",第一條重復(fù)的為False,后面重復(fù)的為True
# 一般不會設(shè)置keep,保持keep為默認(rèn)值。
df.duplicated()

結(jié)果
0    False
1     True
2    False
3    False
4    False
dtype: bool

# keep="last",,最后一條重復(fù)的為False,后面重復(fù)的為True
df.duplicated(keep="last")

結(jié)果
0     True
1    False
2    False
3    False
4    False
dtype: bool

# keep=False,,所有重復(fù)的為True
df.duplicated(keep=False)

結(jié)果
0     True
1     True
2    False
3    False
4    False
dtype: bool

# sub是子,subset是子集
# 標(biāo)記只要brand重復(fù)為重復(fù)值。
df.duplicated(subset='brand')

結(jié)果

0    False
1     True
2    False
3     True
4     True
dtype: bool


# 只要brand重復(fù)brand和style重復(fù)的為重復(fù)值。
df.duplicated(subset=['brand','style'])

結(jié)果

0    False
1     True
2    False
3    False
4     True
dtype: bool


# 顯示重復(fù)記錄,通過布爾索引
df[df.duplicated()]

# 查詢重復(fù)值的個數(shù)。
df.duplicated().sum()

結(jié)果
1

到此這篇關(guān)于pandas中DataFrame檢測重復(fù)值的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)pandas DataFrame檢測重復(fù)值內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

您可能感興趣的文章:
  • Pandas實(shí)現(xiàn)Dataframe的重排和旋轉(zhuǎn)
  • Pandas實(shí)現(xiàn)Dataframe的合并
  • pandas中DataFrame數(shù)據(jù)合并連接(merge、join、concat)
  • 教你漂亮打印Pandas DataFrames和Series
  • 使用pandas忽略行列索引,縱向拼接多個dataframe
  • Pandas.DataFrame轉(zhuǎn)置的實(shí)現(xiàn)
  • Pandas中DataFrame交換列順序的方法實(shí)現(xiàn)
  • 詳解pandas中利用DataFrame對象的.loc[]、.iloc[]方法抽取數(shù)據(jù)
  • Pandas中兩個dataframe的交集和差集的示例代碼
  • Pandas DataFrame求差集的示例代碼
  • 淺談pandas dataframe對除數(shù)是零的處理
  • Pandas中DataFrame數(shù)據(jù)刪除詳情

標(biāo)簽:蘭州 成都 六盤水 江蘇 山東 駐馬店 常州 宿遷

巨人網(wǎng)絡(luò)通訊聲明:本文標(biāo)題《pandas中DataFrame檢測重復(fù)值的實(shí)現(xiàn)》,本文關(guān)鍵詞  pandas,中,DataFrame,檢測,重復(fù),;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時(shí)溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 下面列出與本文章《pandas中DataFrame檢測重復(fù)值的實(shí)現(xiàn)》相關(guān)的同類信息!
  • 本頁收集關(guān)于pandas中DataFrame檢測重復(fù)值的實(shí)現(xiàn)的相關(guān)信息資訊供網(wǎng)民參考!
  • 推薦文章
    资源县| 七台河市| 永修县| 恭城| 台中市| 绥棱县| 夏津县| 浦县| 淳安县| 扎鲁特旗| 平安县| 荔浦县| 曲周县| 芒康县| 沂南县| 哈尔滨市| 海原县| 天门市| 遵义县| 宁阳县| 定安县| 舒兰市| 奈曼旗| 浙江省| 井冈山市| 全州县| 邓州市| 井研县| 章丘市| 昆山市| 讷河市| 永州市| 大新县| 南安市| 台中市| 和平县| 资兴市| 阿克陶县| 霍邱县| 古丈县| 皋兰县|