Pandas- groupby မှ ဘားကွက်တစ်ခု ဖန်တီးနည်း
ပန်ဒါရှိ GroupBy လုပ်ဆောင်ချက်မှ ဘားကွက်တစ်ခုကို ဖန်တီးရန် အောက်ပါ syntax ကို သင်အသုံးပြုနိုင်ပါသည်။
#calculate sum of values by group df_groups = df. groupby ([' group_var '])[' values_var ']. sum () #create bar plot by group df_groups. plot (kind=' bar ')
အောက်ဖော်ပြပါ ဥပမာသည် ဤ syntax ကို လက်တွေ့တွင် မည်သို့အသုံးပြုရမည်ကို ပြသထားသည်။
ဥပမာ- Pandas ရှိ GroupBy မှ Bar Plot တစ်ခုကို ဖန်တီးပါ။
ကျွန်ုပ်တို့တွင် မတူညီသောအသင်းများမှ ဘတ်စကက်ဘောကစားသမားများမှ ရမှတ်များကိုပြသသည့် အောက်ပါပန်ဒါ DataFrame ရှိသည်ဆိုပါစို့။
import pandas as pd
#createDataFrame
df = pd. DataFrame ({' team ': ['A', 'A', 'A', 'A', 'A',
'B', 'B', 'B', 'B', 'B',
'C', 'C', 'C', 'C', 'C'],
' points ': [12, 29, 34, 14, 10, 11, 7, 36,
34, 22, 41, 40, 45, 36, 38]})
#view first five rows of DataFrame
df. head ()
team points
0 to 12
1 to 29
2 to 34
3 to 14
4 to 10
အသင်းတစ်သင်းစီမှ ရမှတ်များ၏ ပေါင်းလဒ်ကို တွက်ချက်ရန်နှင့် အသင်းတစ်ခုစီ၏ ပေါင်းလဒ်ကို မြင်သာစေရန် ဘားဇယားတစ်ခု ဖန်တီးရန် အောက်ပါ syntax ကို အသုံးပြုနိုင်ပါသည်။
import matplotlib. pyplot as plt
#calculate sum of points for each team
df. groupby (' team ')[' points ']. sum ()
#create bar plot by group
df_groups. plot (kind=' bar ')

x-axis သည် အဖွဲ့တစ်ခုစီ၏အမည်ကိုပြသပြီး y-axis သည် အသင်းတစ်ခုစီမှရမှတ်ပေါင်းစုခြင်းကိုပြသသည်။
ဇာတ်ကွက်အနည်းငယ် ပိုကောင်းစေရန် အောက်ဖော်ပြပါ ကုဒ်ကိုလည်း အသုံးပြုနိုင်ပါသည်။
import matplotlib. pyplot as plt
#calculate sum of points for each team
df_groups = df. groupby ([' team '])[' points ']. sum ()
#create bar plot with custom aesthetics
df_groups. plot (kind=' bar ', title=' Total Points by Team ',
ylabel=' Total Points ' , xlabel=' Team ', figsize=( 10,6 ) )
#rotate x-axis ticks vertically
plt. xticks (rotation= 0 )

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