Pandas dataframe (ဥပမာများနှင့်အတူ) ထပ်တူများကိုရှာဖွေနည်း


pandas DataFrame တွင် ထပ်နေသောတန်ဖိုးများကို ရှာဖွေရန် duplicated() လုပ်ဆောင်ချက်ကို သင်သုံးနိုင်သည်။

ဤလုပ်ဆောင်ချက်သည် အောက်ပါအခြေခံ syntax ကိုအသုံးပြုသည်-

 #find duplicate rows across all columns
duplicateRows = df[df. duplicated ()]

#find duplicate rows across specific columns
duplicateRows = df[df. duplicated ([' col1 ',' col2 '])]

အောက်ဖော်ပြပါနမူနာများသည် အောက်ပါပန်ဒါများ DataFrame ဖြင့် ဤလုပ်ဆောင်ချက်ကို လက်တွေ့အသုံးပြုနည်းကို ပြသသည်-

 import pandas as pd

#createDataFrame
df = pd. DataFrame ({' team ': ['A', 'A', 'A', 'A', 'B', 'B', 'B', 'B'],
                   ' points ': [10, 10, 12, 12, 15, 17, 20, 20],
                   ' assists ': [5, 5, 7, 9, 12, 9, 6, 6]})

#view DataFrame
print (df)

  team points assists
0 to 10 5
1 to 10 5
2 to 12 7
3 to 12 9
4 B 15 12
5 B 17 9
6 B 20 6
7 B 20 6

ဥပမာ 1- ကော်လံအားလုံးတွင် ထပ်နေသောအတန်းများကို ရှာပါ။

အောက်ပါကုဒ်သည် DataFrame ၏ကော်လံအားလုံးတွင် ထပ်နေသောအတန်းများကို မည်သို့ရှာဖွေရမည်ကို ပြသသည်-

 #identify duplicate rows
duplicateRows = df[df. duplicated ()]

#view duplicate rows
duplicateRows

        team points assists
1 to 10 5
7 B 20 6

DataFrame တွင် အခြားအတန်းများ၏ အတိအကျ ထပ်နေသော အတန်းနှစ်တန်း ရှိပါသည်။

ပထမထပ်နေသောမျဥ်းများကိုပြသရန် keep=’last’ အငြင်းအခုံကိုလည်း အသုံးပြုနိုင်ကြောင်း သတိပြုပါ-

 #identify duplicate rows
duplicateRows = df[df. duplicated (keep=' last ')]

#view duplicate rows
print (duplicateRows)

	team points assists
0 to 10 5
6 B 20 6

ဥပမာ 2- သီးခြားကော်လံများတွင် ထပ်နေသောအတန်းများကို ရှာပါ။

အောက်ပါကုဒ်သည် DataFrame ၏ “ team” နှင့် “ points” ကော်လံများတွင်သာ ထပ်နေသောအတန်းများကို မည်သို့ရှာဖွေရမည်ကို ပြသသည်-

 #identify duplicate rows across 'team' and 'points' columns
duplicateRows = df[df. duplicated ([' team ',' points '])]

#view duplicate rows
print (duplicateRows)

        team points assists
1 to 10 5
3 to 12 9
7 B 20 6

“အဖွဲ့” နှင့် “အမှတ်များ” ကော်လံများရှိ တန်ဖိုးများသည် ယခင်အတန်းများ၏ အတိအကျမိတ္တူများဖြစ်သည့် အတန်းသုံးတန်းရှိသည်။

ဥပမာ 3- ကော်လံတစ်ခုတွင် ထပ်နေသောအတန်းများကို ရှာပါ။

အောက်ပါကုဒ်သည် DataFrame ၏ “ အဖွဲ့” ကော်လံတွင်သာ ထပ်နေသောအတန်းများကို မည်သို့ရှာဖွေရမည်ကို ပြသသည်-

 #identify duplicate rows in 'team' column
duplicateRows = df[df. duplicated ([' team '])]

#view duplicate rows
print (duplicateRows)

	team points assists
1 to 10 5
2 to 12 7
3 to 12 9
5 B 17 9
6 B 20 6
7 B 20 6

“ အဖွဲ့” ကော်လံရှိ တန်ဖိုးများသည် ယခင်အတန်းများ၏ အတိအကျ ထပ်နေမည့် စုစုပေါင်း အတန်းခြောက်တန်း ရှိပါသည်။

ထပ်လောင်းအရင်းအမြစ်များ

အောက်ဖော်ပြပါ သင်ခန်းစာများသည် ပန်ဒါများတွင် အခြားဘုံလုပ်ဆောင်ချက်များကို မည်သို့လုပ်ဆောင်ရမည်ကို ရှင်းပြသည်-

Pandas တွင် ထပ်နေသောအတန်းများကို ဖယ်ရှားနည်း
Pandas ရှိ ထပ်နေသောကော်လံများကို ဖယ်ရှားနည်း
Pandas ရှိ အညွှန်းအလိုက် ကော်လံများကို မည်သို့ရွေးချယ်ရမည်နည်း။

မှတ်ချက်တစ်ခုထည့်ပါ။

သင့် email လိပ်စာကို ဖော်ပြမည် မဟုတ်ပါ။ လိုအပ်သော ကွက်လပ်များကို * ဖြင့်မှတ်သားထားသည်