Pandas- တစ်စိတ်တစ်ပိုင်း ကိုက်ညီမှုအပေါ် အခြေခံ၍ ကော်လံများကို ရွေးချယ်နည်း
တစ်စိတ်တစ်ပိုင်း ကိုက်ညီမှုအပေါ် အခြေခံ၍ ပန်ဒါ DataFrame ရှိ ကော်လံများကို ရွေးချယ်ရန် အောက်ပါနည်းလမ်းများကို သင်အသုံးပြုနိုင်သည်-
နည်းလမ်း 1- တစ်စိတ်တစ်ပိုင်း ကိုက်ညီမှုအပေါ် အခြေခံ၍ ကော်လံများကို ရွေးပါ။
#select columns that contain 'team'
df. loc [:, df. columns . str . contains (' team ')]
နည်းလမ်း 2- တစ်စိတ်တစ်ပိုင်း ကိုက်ညီမှုများစွာကို အခြေခံ၍ ကော်လံများကို ရွေးပါ။
#select columns that contain 'team' or 'rebounds'
df. loc [:, df. columns . str . contains (' team|rebounds ')]
အောက်ပါနမူနာများသည် အောက်ပါ pandas DataFrame ဖြင့် နည်းလမ်းတစ်ခုစီကို အသုံးပြုနည်းကို ပြသသည်-
import pandas as pd #createDataFrame df = pd. DataFrame ({' team_name ': ['A', 'A', 'A', 'A', 'B', 'B', 'B', 'B'], ' team_points ': [5, 7, 7, 9, 12, 9, 9, 4], ' assists ': [11, 8, 10, 6, 6, 5, 9, 12], ' rebounds ': [6, 7, 7, 6, 10, 12, 10, 9]}) #view DataFrame print (df) team_name team_points assists rebounds 0 A 5 11 6 1 To 7 8 7 2 To 7 10 7 3 to 9 6 6 4 B 12 6 10 5 B 9 5 12 6 B 9 9 10 7 B 4 12 9
ဥပမာ 1- တစ်စိတ်တစ်ပိုင်း ကိုက်ညီမှုအပေါ် အခြေခံ၍ ကော်လံများကို ရွေးပါ။
အောက်ပါကုဒ်သည် ကော်လံအမည်တွင် “ အဖွဲ့” ပါရှိသော pandas DataFrame ရှိ ကော်လံအားလုံးကို မည်သို့ရွေးချယ်ရမည်ကို ပြသသည်-
#select columns that contain 'team'
df_team_cols = df. loc [:, df. columns . str . contains (' team ')]
#view results
print (df_team_cols)
team_name team_points
0 to 5
1 to 7
2 to 7
3 to 9
4 B 12
5 B 9
6 B 9
7 B 4
အမည်ရှိ “ အဖွဲ့” ပါသော ကော်လံနှစ်ခုလုံးကို ပြန်ပေးကြောင်း သတိပြုပါ။
ဥပမာ 2- တစ်စိတ်တစ်ပိုင်း ကိုက်ညီမှုများစွာကို အခြေခံ၍ ကော်လံများကို ရွေးပါ။
အောက်ပါကုဒ်သည် ကော်လံအမည်တွင် “ team” သို့မဟုတ် “ bounces” ပါရှိသော pandas DataFrame ရှိ ကော်လံအားလုံးကို မည်သို့ရွေးချယ်ရမည်ကို ပြသသည်-
#select columns that contain 'team' or 'rebounds'
df_team_rebs = df. loc [:, df. columns . str . contains (' team|rebounds ')]
#view results
print (df_team_rebs)
team_name team_points rebounds
0 to 5 6
1 To 7 7
2 to 7 7
3 to 9 6
4 B 12 10
5 B 9 12
6 B 9 10
7 B 4 9
အမည်ရှိ “ team” သို့မဟုတ် “ rebounds” ပါရှိသော ကော်လံအားလုံးကို ပြန်ပို့ပေးပါသည်။
မှတ်ချက် : | အော်ပရေတာသည် ပန်ဒါများတွင် “ OR” ကို ကိုယ်စားပြုသည်။
သင်အလိုရှိသလောက် တစ်စိတ်တစ်ပိုင်းစာကြောင်းများ ကိုက်ညီမှုများစွာကို ရှာဖွေလိုသကဲ့သို့ ဤအော်ပရေတာများစွာကို အခမဲ့အသုံးပြုနိုင်ပါသည်။
ထပ်လောင်းအရင်းအမြစ်များ
အောက်ဖော်ပြပါ သင်ခန်းစာများသည် ပန်ဒါများတွင် အခြားဘုံလုပ်ဆောင်ချက်များကို မည်သို့လုပ်ဆောင်ရမည်ကို ရှင်းပြသည်-
Pandas တွင် နာမည်ဖြင့် ကော်လံများကို မည်သို့ရွေးချယ်ရမည်နည်း။
Pandas ရှိ အညွှန်းအလိုက် ကော်လံများကို မည်သို့ရွေးချယ်ရမည်နည်း။
Pandas တွင် ဒေတာအမျိုးအစားအလိုက် ကော်လံများကို မည်သို့ရွေးချယ်ရမည်နည်း။