Pandas- ကော်လံတစ်ခုတွင် ထူးခြားသောတန်ဖိုးများကို မည်သို့ရှာမည်နည်း။
Pandas DataFrame ကော်လံရှိ ထူးခြားသောတန်ဖိုးများစာရင်းကို ရရှိရန် အလွယ်ကူဆုံးနည်းလမ်းမှာ unique() လုပ်ဆောင်ချက်ကို အသုံးပြုခြင်းဖြစ်သည်။
ဤသင်ခန်းစာတွင် အောက်ပါ pandas DataFrame ဖြင့် ဤလုပ်ဆောင်ချက်ကို အသုံးပြုခြင်း၏ ဥပမာများစွာကို ပေးပါသည်။
import pandas as pd #createDataFrame df = pd. DataFrame ({' team ': ['A', 'A', 'A', 'B', 'B', 'C'], ' conference ': ['East', 'East', 'East', 'West', 'West', 'East'], ' points ': [11, 8, 10, 6, 6, 5]}) #view DataFrame df team conference points 0 A East 11 1 A East 8 2 A East 10 3 B West 6 4 B West 6 5 C East 5
ကော်လံတစ်ခုတွင် ထူးခြားသောတန်ဖိုးများကို ရှာပါ။
အောက်ပါကုဒ်သည် DataFrame ကော်လံတစ်ခုတည်းတွင် ထူးခြားသောတန်ဖိုးများကို မည်သို့ရှာဖွေရမည်ကို ပြသသည်-
df. team . single () array(['A', 'B', 'C'], dtype=object)
အဖွဲ့ကော်လံရှိ ထူးခြားသောတန်ဖိုးများတွင် “ A” “ B” နှင့် “ C” တို့ ပါဝင်သည်ကို ကျွန်ုပ်တို့တွေ့မြင်နိုင်ပါသည်။
ကော်လံအားလုံးတွင် ထူးခြားသောတန်ဖိုးများကို ရှာပါ။
အောက်ပါကုဒ်သည် DataFrame ကော်လံအားလုံးတွင် ထူးခြားသောတန်ဖိုးများကို မည်သို့ရှာဖွေရမည်ကို ပြသသည်-
for col in df: print (df[col] .unique ()) ['A' 'B' 'C'] ['East' 'West'] [11 8 10 6 5]
ကော်လံတစ်ခုတွင် ထူးခြားသောတန်ဖိုးများကို ရှာပြီး စီပါ။
အောက်ပါကုဒ်သည် DataFrame ၏ကော်လံတစ်ခုတည်းတွင် ထူးခြားသောတန်ဖိုးများအလိုက် ရှာဖွေပြီး စီရန်ကိုပြသသည်-
#find unique points values points = df. points . single () #sort values smallest to largest points. sort () #display sorted values points array([ 5, 6, 8, 10, 11])
ကော်လံတစ်ခုတွင် ထူးခြားသောတန်ဖိုးများကို ရှာပြီး ရေတွက်ပါ။
အောက်ဖော်ပြပါ ကုဒ်သည် DataFrame ကော်လံတစ်ခုတွင် ထူးခြားသောတန်ဖိုးများ ဖြစ်ပေါ်မှုကို ရှာဖွေပြီး ရေတွက်ပုံကို ပြသသည်-
df. team . value_counts () At 3 B2 C 1 Name: team, dtype: int64
ထပ်လောင်းအရင်းအမြစ်များ
Pandas DataFrame တွင် အတန်းတစ်တန်းကို မည်သို့ရွေးချယ်ရမည်နည်း။
Pandas ရှိ ကော်လံအများအပြားတွင် ထူးခြားသောတန်ဖိုးများကို မည်သို့ရှာမည်နည်း။