အခြေအနေများစွာတွင် pandas dataframe ကို စစ်ထုတ်နည်း


မကြာခဏ အခြေအနေများစွာတွင် ပန်ဒါ DataFrame ကို စစ်ထုတ်လိုပေမည်။ ကံကောင်းစွာဖြင့်၊ ၎င်းသည် Boolean လုပ်ဆောင်ချက်များကို အသုံးပြု၍ လုပ်ဆောင်ရန် လွယ်ကူသည်။

ဤသင်ခန်းစာသည် အခြေအနေများစွာတွင် အောက်ပါပန်ဒါ DataFrame ကို စစ်ထုတ်နည်း ဥပမာများစွာကို ပေးသည်-

 import pandas as pd

#createDataFrame
df = pd.DataFrame({'team': ['A', 'A', 'B', 'B', 'C'],
                   'points': [25, 12, 15, 14, 19],
                   'assists': [5, 7, 7, 9, 12],
                   'rebounds': [11, 8, 10, 6, 6]})

#view DataFrame 
df

        team points assists rebounds
0 to 25 5 11
1 to 12 7 8
2 B 15 7 10
3 B 14 9 6
4 C 19 12 6

ဥပမာ 1- “and” ကို အသုံးပြု၍ အခြေအနေများစွာကို စစ်ထုတ်ပါ

အောက်ပါကုဒ်သည် DataFrame နှင့် ( & ) အော်ပရေတာကို အသုံးပြု၍ မည်သို့စစ်ထုတ်ရမည်ကို သရုပ်ပြသည်-

 #return only rows where points is greater than 13 and assists is greater than 7
df[(df. points > 13) & (df. assists > 7)]

        team points assists rebounds
3 B 14 9 6
4 C 19 12 6

#return only rows where team is 'A' and points is greater than or equal to 15
df[(df. team == 'A') & (df. points >= 15)]


        team points assists rebounds
0 to 25 5 11

ဥပမာ 2- “သို့မဟုတ်” ကို အသုံးပြု၍ အခြေအနေများစွာကို စစ်ထုတ်ပါ

အောက်ပါကုဒ်သည် DataFrame သို့မဟုတ် ( | ) အော်ပရေတာကို အသုံးပြု၍ DataFrame ကို စစ်ထုတ်ပုံကို သရုပ်ပြသည်-

 #return only rows where points is greater than 13 or assists is greater than 7
df[(df. dots > 13) | (df. assists > 7)]


        team points assists rebounds
0 to 25 5 11
2 B 15 7 10
3 B 14 9 6
4 C 19 12 6

#return only rows where team is 'A' or points is greater than or equal to 15
df[( df.team == 'A') | (df. points >= 15)]

        team points assists rebounds
0 to 25 5 11
1 to 12 7 8
2 B 15 7 10
4 C 19 12 6

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

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

 #define a list of values
filter_list = [12, 14, 15]

#return only rows where points is in the list of values
df[df. points . isin (filter_list)]

	team points assists rebounds
1 to 12 7 8
2 B 15 7 10
3 B 14 9 6

#define another list of values
filter_list2 = ['A', 'C']

#return only rows where team is in the list of values
df[df. team . isin (filter_list2)]


        team points assists rebounds
0 to 25 5 11
1 to 12 7 8
4 C 19 12 6

နောက်ထပ် panda သင်ခန်းစာများကို ဤနေရာတွင် ရှာတွေ့နိုင်ပါသည်။

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

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