Pandas တွင် တစ်ခု သို့မဟုတ် တစ်ခုထက်ပိုသော အညွှန်းတန်ဖိုးများကို မွမ်းမံနည်း
Pandas DataFrame တွင် တစ်ခုတည်းသော အညွှန်းတန်ဖိုးကို မွမ်းမံရန် အောက်ပါ syntax ကို သင်အသုံးပြုနိုင်သည်-
df. rename (index={' Old_Value ':' New_Value '}, inplace= True )
အညွှန်းကိန်းတန်ဖိုးများစွာကို တစ်ပြိုင်နက်တည်းမွမ်းမံရန် အောက်ပါ syntax ကို သင်အသုံးပြုနိုင်သည်-
df. rename (index={' Old1 ':' New1 ', ' Old2 ':' New2 '}, inplace= True )
အောက်ပါဥပမာများသည် ဤ syntax ကိုလက်တွေ့တွင်မည်သို့အသုံးပြုရမည်ကိုပြသထားသည်။
ဥပမာ 1- Pandas DataFrame ရှိ အညွှန်းတန်ဖိုးကို ပြောင်းပါ။
ကျွန်ုပ်တို့တွင် အောက်ပါ ပန်ဒါ DataFrame ရှိသည် ဆိုပါစို့။
import pandas as pd #createDataFrame df = pd. DataFrame ({' team ': ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H'], ' points ': [25, 12, 15, 14, 19, 23, 25, 29], ' assists ': [5, 7, 7, 9, 12, 9, 9, 4], ' rebounds ': [11, 8, 10, 6, 6, 5, 9, 12]}) #make 'team' column the index column df. set_index (' team ', inplace= True ) #view DataFrame df points assists rebounds team A 25 5 11 B 12 7 8 C 15 7 10 D 14 9 6 E 19 12 6 F 23 9 5 G 25 9 9 H 29 4 12
အညွှန်းကော်လံရှိ တန်ဖိုး “ A” ကို “ P” ဖြင့် အစားထိုးရန် အောက်ပါကုဒ်ကို အသုံးပြုနိုင်ပါသည်။
#replace 'A' with 'P' in index
df. rename (index={' A ':' P '}, inplace= True )
#view updated DataFrame
df
points assists rebounds
team
P 25 5 11
B 12 7 8
C 15 7 10
D 14 9 6
E 19 12 6
F 23 9 5
G 25 9 9
H 29 4 12
မူရင်းအညွှန်းတွင် “ A” တန်ဖိုးကို အခြားတန်ဖိုးများအားလုံး တူညီနေချိန်တွင် အစားထိုးထားသည်ကို သတိပြုပါ။
ဥပမာ 2- Pandas DataFrame တွင် အညွှန်းတန်ဖိုးများစွာကို ပြောင်းပါ။
ကျွန်ုပ်တို့တွင် ယခင်ကဲ့သို့ ပန်ဒါ DataFrame ရှိသည် ဆိုပါစို့။
#view DataFrame
df
points assists rebounds
team
A 25 5 11
B 12 7 8
C 15 7 10
D 14 9 6
E 19 12 6
F 23 9 5
G 25 9 9
H 29 4 12
အညွှန်းကော်လံရှိ “ A” နှင့် “ B” တန်ဖိုးများကို အစားထိုးရန် အောက်ပါကုဒ်များကို အသုံးပြုနိုင်ပါသည်။
#replace 'A' with 'P' and replace 'B' with 'Q' in index
df. rename (index={' A ':' P ', ' B ':' Q '}, inplace= True )
#view updated DataFrame
df
points assists rebounds
team
P 25 5 11
Q 12 7 8
C 15 7 10
D 14 9 6
E 19 12 6
F 23 9 5
G 25 9 9
H 29 4 12
မူရင်းအညွှန်းတွင် “ A” နှင့် “ B” တန်ဖိုးများကို အစားထိုးခဲ့ပြီး အခြားတန်ဖိုးများအားလုံးသည် တူညီနေခဲ့သည်။
အညွှန်းကိန်းတွင် သင်လိုချင်သလောက် တန်ဖိုးများစွာကို အစားထိုးရန် အတိအကျတူညီသော အထားအသိုကို အသုံးပြုနိုင်သည်။
ထပ်လောင်းအရင်းအမြစ်များ
အောက်ဖော်ပြပါ သင်ခန်းစာများသည် ပန်ဒါများတွင် အခြားဘုံလုပ်ဆောင်ချက်များကို မည်သို့လုပ်ဆောင်ရမည်ကို ရှင်းပြသည်-
Pandas DataFrame တွင် အညွှန်းတစ်ခုကို ပြန်လည်သတ်မှတ်နည်း
Pandas တွင် ကော်လံကို အညွှန်းအဖြစ် သတ်မှတ်နည်း
Pandas ရှိ အညွှန်းကို ကော်လံသို့ မည်သို့ပြောင်းရမည်နည်း။