Pandas- dataframes နှစ်ခုကို ဘယ်လို နုတ်မလဲ။
ပန်ဒါတစ်ခု DataFrame ကို အခြားတစ်ခုမှ နုတ်ရန် အောက်ပါ syntax ကို သင်သုံးနိုင်သည်။
df1. subtract (df2)
သင့်တွင် DataFrame တစ်ခုစီတွင် ဇာတ်ကောင်ကော်လံတစ်ခုရှိနေပါက၊ DataFrame တစ်ခုစီ၏ အညွှန်းကော်လံသို့ ဦးစွာရွှေ့ရန် လိုအပ်နိုင်သည်-
df1. set_index (' char_column '). subtract ( df2.set_index (' char_column '))
အောက်ပါဥပမာများသည် syntax တစ်ခုစီကို လက်တွေ့တွင် မည်သို့အသုံးပြုရမည်ကို ပြသထားသည်။
ဥပမာ 1- Pandas DataFrames နှစ်ခုကို နုတ်ပါ (ဂဏန်းကော်လံများသာ)
ကျွန်ုပ်တို့တွင် ဂဏန်းကော်လံများသာရှိသော အောက်ပါပန်ဒါ DataFrames နှစ်ခုရှိသည် ဆိုကြပါစို့။
import pandas as pd #create first DataFrame df1 = pd. DataFrame ({' points ': [5, 17, 7, 19, 12, 13, 9, 24], ' assists ': [4, 7, 7, 6, 8, 7, 10, 11]}) print (df1) assist points 0 5 4 1 17 7 2 7 7 3 19 6 4 12 8 5 13 7 6 9 10 7 24 11 #create second DataFrame df2 = pd. DataFrame ({' points ': [4, 22, 10, 3, 7, 8, 12, 10], ' assists ': [3, 5, 5, 4, 7, 14, 9, 5]}) print (df2) assist points 0 4 3 1 22 5 2 10 5 3 3 4 4 7 7 5 8 14 6 12 9 7 10 5
အောက်ပါကုဒ်သည် DataFrames နှစ်ခုကြားရှိ သက်ဆိုင်ရာတန်ဖိုးများကို နုတ်နည်းကိုပြသသည်-
#subtract corresponding values between the two DataFrames
df1. subtract (df2)
assist points
0 1 1
1 -5 2
2 -3 2
3 16 2
4 5 1
5 5 -7
6 -3 1
7 14 6
ဥပမာ 2- Pandas DataFrames နှစ်ခု (ဇာတ်ကောင်နှင့် ဂဏန်းကော်လံများ ရောနှောခြင်း)
တစ်ခုစီတွင် team ဟုခေါ်သော ဇာတ်ကောင်ကော်လံတစ်ခုစီတွင် အောက်ပါပန်ဒါ DataFrames နှစ်ခုရှိသည် ဆိုကြပါစို့။
import pandas as pd #create first DataFrame df1 = pd. DataFrame ({' team ': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'], ' points ': [5, 17, 7, 19, 12, 13, 9, 24], ' assists ': [4, 7, 7, 6, 8, 7, 10, 11]}) print (df1) team points assists 0 to 5 4 1 B 17 7 2 C 7 7 3 D 19 6 4 E 12 8 5 F 13 7 6 G 9 10 7:24 a.m. 11 #create second DataFrame df2 = pd. DataFrame ({' team ': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'], ' points ': [4, 22, 10, 3, 7, 8, 12, 10], ' assists ': [3, 5, 5, 4, 7, 14, 9, 3]}) print (df2) team points assists 0 to 4 3 1 B 22 5 2 C 10 5 3 D 3 4 4 E 7 7 5 F 8 14 6 G 12 9 7:10 a.m. 3
အောက်ပါကုဒ်သည် အဖွဲ့ ကော်လံကို DataFrame တစ်ခုစီ၏ အညွှန်းကော်လံသို့ မည်သို့ရွှေ့ရမည်ကို ပြသထားပြီး DataFrames နှစ်ခုကြားရှိ သက်ဆိုင်ရာတန်ဖိုးများကို နုတ်ယူပါ။
#move 'team' column to index of each DataFrame and subtract corresponding values
df1. set_index (' team '). subtract ( df2.set_index (' team '))
assist points
team
At 1 1
B-52
C -3 2
D 16 2
E 5 1
F 5 -7
G -3 1
H 14 8
ထပ်လောင်းအရင်းအမြစ်များ
အောက်ဖော်ပြပါ သင်ခန်းစာများသည် ပန်ဒါများတွင် အခြားဘုံအလုပ်များကို မည်သို့လုပ်ဆောင်ရမည်ကို ရှင်းပြသည်-
Pandas- ကော်လံနှစ်ခုကြား ခြားနားချက်ကို ဘယ်လိုရှာမလဲ။
Pandas- စာကြောင်းနှစ်ခုကြား ခြားနားချက်ကို ဘယ်လိုရှာမလဲ။
Pandas- ကော်လံနှစ်ခုကို နုတ်နည်း