Pandas- ကော်လံများကို အဘိဓာန်ဖြင့် အမည်ပြောင်းနည်း


ပန်ဒါများတွင် အဘိဓာန်တစ်ခုဖြင့် ကော်လံများကို အမည်ပြောင်းရန် အောက်ပါအခြေခံ syntax ကို သင်အသုံးပြုနိုင်သည်-

 #define dictionary
some_dict = {' old_col1 ': ' new_col1 ',
             ' old_col2 ': ' new_col2 ',
             ' old_col3 ': ' new_col3 '}
 
#rename columns in DataFrame using dictionary
df. rename (columns=some_dict, inplace= True )

မှတ်ချက် – မူရင်း DataFrame ၏ကော်လံအမည်များကို မွမ်းမံရန်အတွက် inplace=True ကို သတ်မှတ်ရပါမည်။

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

ဥပမာ- Pandas ရှိ ကော်လံများကို အဘိဓာန်ဖြင့် အမည်ပြောင်းပါ။

ကျွန်ုပ်တို့တွင် အောက်ပါ ပန်ဒါ DataFrame ရှိသည် ဆိုပါစို့။

 import pandas as pd

#createDataFrame
df = pd. DataFrame ({' rebounds ': [10, 14, 14, 13, 13, 12, 10, 7],
                    ' points ': [30, 22, 19, 14, 14, 11, 20, 28],
                    ' assists ': [5, 6, 6, 5, 8, 7, 7, 9]})

#view DataFrame
print (df)

   rebound points assists
0 10 30 5
1 14 22 6
2 14 19 6
3 13 14 5
4 13 14 8
5 12 11 7
6 10 20 7
7 7 28 9

အဘိဓာန်ကို အသုံးပြု၍ DataFrame ရှိ ကော်လံတစ်ခုစီကို အမည်ပြောင်းရန် အောက်ပါ syntax ကို အသုံးပြုနိုင်ပါသည်။

 #define dictionary with new column names
some_dict = {' rebounds ': ' rebs ',
             ' points ': ' pts ',
             ' assists ': ' ast '}
 
#rename columns in DataFrame using dictionary
df. rename (columns=some_dict, inplace= True )

#view updated DataFrame
print (df)

   rebs pts ast
0 10 30 5
1 14 22 6
2 14 19 6
3 13 14 5
4 13 14 8
5 12 11 7
6 10 20 7
7 7 28 9

အဘိဓာန်တွင် ကျွန်ုပ်တို့သတ်မှတ်ထားသော တန်ဖိုးများအလိုက် ကော်လံတစ်ခုစီကို အမည်ပြောင်းထားသည်ကို သတိပြုပါ။

အဘိဓာန်ကို အသုံးပြု၍ ကော်လံတိုင်းကို အမည်ပြောင်းရန် မလိုအပ်ကြောင်း သတိပြုသင့်သည်။

ဥပမာအားဖြင့်၊ DataFrame ၏ ကော်လံများကို အမှတ်များ သာ အမည်ပြောင်းပြီး ကူညီပေးရန် အတွက် အဘိဓာန်တစ်ခု ဖန်တီးနိုင်သည်-

 #define dictionary with new column names for points and assists only
some_dict = {' points ':' pts ',
             ' assists ': ' ast '}
 
#rename columns in DataFrame using dictionary
df. rename (columns=some_dict, inplace= True )

#view updated DataFrame
print (df)

   rebounds pts ast
0 10 30 5
1 14 22 6
2 14 19 6
3 13 14 5
4 13 14 8
5 12 11 7
6 10 20 7
7 7 28 9

အမှတ်များ နှင့် အထောက်အကူပြု ကော်လံများကိုသာ အမည်ပြောင်းထားသည်။

bounces ကော်လံကို အဘိဓာန်တွင် မပါဝင်သောကြောင့်၊ ၎င်းကို DataFrame တွင် အမည်မပြောင်းပါ။

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

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

Pandas တွင် ကော်လံအမည်များအားလုံးကို စာရင်းပြုစုနည်း
Pandas တွင် ကော်လံများကို နာမည်ဖြင့် စီနည်း
Pandas ရှိ ထပ်နေသောကော်လံများကို ဖယ်ရှားနည်း

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

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