Pandas- တန်ဖိုးအလိုက် စီးရီးများကို စစ်ထုတ်နည်း
ပန်ဒါစီးရီးတစ်ခုရှိ တန်ဖိုးများကို စစ်ထုတ်ရန် အောက်ပါနည်းလမ်းများကို သင်အသုံးပြုနိုင်သည်-
နည်းလမ်း 1- အခြေအနေတစ်ခုတည်းအပေါ် အခြေခံ၍ တန်ဖိုးများကို စစ်ထုတ်ပါ။
#filter for values equal to 7 my_series. loc [ lambda x:x == 7]
နည်းလမ်း 2- “OR” အခြေအနေကို အသုံးပြု၍ တန်ဖိုးများကို စစ်ထုတ်ပါ။
#filter for values less than 10 or greater than 20 my_series. loc [ lambda x: (x < 10) | (x > 20)]
နည်းလမ်း 3- “ AND” အခြေအနေကို အသုံးပြု၍ တန်ဖိုးများကို စစ်ထုတ်ပါ။
#filter for values greater than 10 and less than 20 my_series. loc [ lambda x: (x > 10) & (x < 20)]
နည်းလမ်း 4: စာရင်းတွင်ပါရှိသောတန်ဖိုးများကိုစစ်ထုတ်ပါ။
#filter for values that are equal to 4, 7, or 23 my_series[my_series. isin ([4, 7, 23])]
ဤသင်ခန်းစာတွင် အောက်ပါ pandas series ဖြင့် လက်တွေ့တွင် နည်းလမ်းတစ်ခုစီကို အသုံးပြုပုံကို ရှင်းပြထားသည်။
import pandas as pd
#create pandas Series
data = pd. Series ([4, 7, 7, 12, 19, 23, 25, 30])
#view pandas Series
print (data)
0 4
1 7
2 7
3 12
4 19
5 23
6 25
7 30
dtype: int64
ဥပမာ 1: အခြေအနေတစ်ခုအပေါ် အခြေခံ၍ တန်ဖိုးများကို စစ်ထုတ်ပါ။
အောက်ပါကုဒ်သည် 7 နှင့်ညီမျှသောတန်ဖိုးများအတွက်ပန်ဒါစီးရီးများကိုစစ်ထုတ်နည်းကိုပြသသည်-
#filter for values equal to 7 data. loc [ lambda x:x == 7] 1 7 2 7 dtype: int64
7 နှင့် မညီသော တန်ဖိုးများကို စစ်ထုတ်နိုင်သည်။
#filter for values not equal to 7 data. loc [ lambda x:x != 7] 0 4 3 12 4 19 5 23 6 25 7 30 dtype: int644
ဥပမာ 2- “OR” အခြေအနေကို အသုံးပြု၍ တန်ဖိုးများကို စစ်ထုတ်ပါ။
အောက်ပါကုဒ်သည် တန်ဖိုး 10 ထက်နည်းသော သို့မဟုတ် 20 ထက်ကြီးသောတန်ဖိုးများအတွက် ပန်ဒါစီးရီးကို စစ်ထုတ်နည်းကို ပြသသည်-
#filter for values less than 10 or greater than 20 data. loc [ lambda x: (x < 10) | (x > 20)] 0 4 1 7 2 7 5 23 6 25 7 30 dtype: int64
ဥပမာ 3- “AND” အခြေအနေကို အသုံးပြု၍ တန်ဖိုးများကို စစ်ထုတ်ပါ။
အောက်ပါကုဒ်သည် 10 နှင့် 20 အောက်တန်ဖိုးများအတွက် ပန်ဒါစီးရီးများကို စစ်ထုတ်နည်းကို ပြသသည်-
#filter for values greater than 10 and less than 20 data. loc [ lambda x: (x > 10) & (x < 20)] 3 12 4 19 dtype: int64
ဥပမာ 4: စာရင်းတွင်ပါရှိသောတန်ဖိုးများကိုစစ်ထုတ်ပါ။
အောက်ပါကုဒ်သည် စာရင်းတစ်ခုတွင်ပါရှိသော တန်ဖိုးများအတွက် ပန်ဒါစီးရီးများကို စစ်ထုတ်နည်းကို ပြသသည်-
#filter for values that are equal to 4, 7, or 23 data[data. isin ([4, 7, 23])] 0 4 1 7 2 7 5 23 dtype: int64
ထပ်လောင်းအရင်းအမြစ်များ
အောက်ဖော်ပြပါ သင်ခန်းစာများသည် Python တွင် အခြားသော ဘုံ filtering လုပ်ဆောင်ချက်များကို မည်သို့လုပ်ဆောင်ရမည်ကို ရှင်းပြသည်-
သတ်မှတ်ထားသောစာကြောင်းပါရှိသော Pandas DataFrame အတန်းများကို စစ်ထုတ်နည်း
အခြေအနေများစွာတွင် Pandas DataFrame ကို စစ်ထုတ်နည်း
Pandas DataFrame တွင် “ မဝင်ပါ” စစ်ထုတ်နည်းကို အသုံးပြုနည်း