Pandas- ကော်လံနှစ်ခုကြား ခြားနားချက်ကို ဘယ်လိုရှာမလဲ။


pandas DataFrame ရှိ ကော်လံနှစ်ခုကြား ခြားနားချက်ကို ရှာဖွေရန်၊ သင်သည် အောက်ပါ syntax ကို အသုံးပြုနိုင်သည်။

 df[' difference '] = df[' column1 '] - df[' column2 ']

အောက်ပါဥပမာများသည် ဤ syntax ကိုလက်တွေ့တွင်မည်သို့အသုံးပြုရမည်ကိုပြသထားသည်။

ဥပမာ 1- ကော်လံနှစ်ခုကြား ခြားနားချက်ကို ရှာပါ။

ရှစ်နှစ်ဆက်တိုက် အရောင်းကာလအတွက် ဒေသနှစ်ခု (A နှင့် B) အတွက် စုစုပေါင်းရောင်းအားကို ပြသသည့် အောက်ပါပန်ဒါ DataFrame ရှိသည်ဆိုပါစို့။

 import pandas as pd

#createDataFrame
df = pd. DataFrame ({' period ': [1, 2, 3, 4, 5, 6, 7, 8],
                   ' A_sales ': [12, 14, 15, 13, 18, 20, 19, 24],
                   ' B_sales ': [14, 19, 20, 22, 24, 20, 17, 23]})

#view DataFrame
df

period A_sales B_sales
0 1 12 14
1 2 14 19
2 3 15 20
3 4 13 22
4 5 18 24
5 6 20 20
6 7 19 17
7 8 24 23

အောက်ပါကုဒ်သည် အရောင်းကာလတစ်ခုစီအတွက် Region B နှင့် Region A အရောင်းအကြား ကွာခြားချက်ကို တွက်ချက်နည်းကို ပြသသည်-

 #add new column to represent difference between B sales and A sales
df[' diff '] = df[' B_sales '] - df[' A_sales ']

#view DataFrame
df

        period A_sales B_sales diff
0 1 12 14 2
1 2 14 19 5
2 3 15 20 5
3 4 13 22 9
4 5 18 24 6
5 6 20 20 0
6 7 19 17 -2
7 8 24 23 -1

pandas.Series.abs() လုပ်ဆောင်ချက်ကို အသုံးပြု၍ ရောင်းချမှု၌ လုံးဝခြားနားချက်ကို တွက်ချက်နိုင်သည်-

 #add new column to represent absolute difference between B sales and A sales
df[' diff '] = pd. Series . abs (df[' B_sales '] - df[' A_sales '])

#view DataFrame
df

	period A_sales B_sales diff
0 1 12 14 2
1 2 14 19 5
2 3 15 20 5
3 4 13 22 9
4 5 18 24 6
5 6 20 20 0
6 7 19 17 2
7 8 24 23 1

ဥပမာ 2- အခြေအနေပေါ်မူတည်၍ ကော်လံများကြား ခြားနားချက်ကို ရှာပါ။

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

ဥပမာအားဖြင့်၊ အောက်ပါကုဒ်သည် တိုင်းဒေသကြီး A တွင် အရောင်းအ၀ယ်သည် တိုင်းဒေသကြီး B တွင်ရောင်းချမှုထက် ကြီးသော အတန်းများကိုသာ ပြန်ပေးသည်-

 #add new column to represent difference between B sales and A sales
df[' diff '] = df[' B_sales '] - df[' A_sales ']

#display rows where sales in region A is greater than sales in region B
df[df[' diff ']< 0 ]


        period A_sales B_sales diff
6 7 19 17 -2
7 8 24 23 -1

ထပ်လောင်းအရင်းအမြစ်များ

Pandas- စာကြောင်းနှစ်ခုကြား ခြားနားချက်ကို ဘယ်လိုရှာမလဲ။
Pandas- ကော်လံအများအပြားတွင် အုပ်စုဖွဲ့၍ စုစည်းနည်း

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

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