Pandas- ကော်လံအမည်များတွင် နောက်ဆက်တွဲထည့်နည်း


Pandas DataFrame ရှိ ကော်လံအမည်များသို့ နောက်ဆက်တွဲတစ်ခုထည့်ရန် အောက်ပါနည်းလမ်းများကို သင်အသုံးပြုနိုင်ပါသည်။

နည်းလမ်း 1- ကော်လံအမည်များအားလုံးတွင် နောက်ဆက်တွဲတစ်ခု ထည့်ပါ။

 df = df. add_suffix (' _my_suffix ')

နည်းလမ်း 2- သီးခြားကော်လံအမည်များသို့ နောက်ဆက်တွဲတစ်ခု ထည့်ပါ။

 #specify columns to add suffix to
cols = [' col1 ', ' col3 ']

#add suffix to specific columns
df = df. rename (columns={c: c+' _my_suffix ' for c in df. columns if c in cols})

အောက်ပါနမူနာများသည် အောက်ပါ pandas DataFrame ဖြင့် ဤနည်းလမ်းတစ်ခုစီကို အသုံးပြုနည်းကို ပြသသည်-

 import pandas as pd

#createDataFrame
df = pd. DataFrame ({' points ': [25, 12, 15, 14, 19, 23],
                   ' assists ': [5, 7, 7, 9, 12, 9],
                   ' rebounds ': [11, 8, 10, 6, 6, 5],
                   ' blocks ': [6, 6, 3, 2, 7, 9]})

#view DataFrame
print (df)

   points assists rebounds blocks
0 25 5 11 6
1 12 7 8 6
2 15 7 10 3
3 14 9 6 2
4 19 12 6 7
5 23 9 5 9

နည်းလမ်း 1- ကော်လံအမည်များအားလုံးတွင် နောက်ဆက်တွဲတစ်ခု ထည့်ပါ။

အောက်ပါကုဒ်သည် ကော်လံအမည်များအားလုံးတွင် suffix “ _total” ကို ထည့်သွင်းနည်းကို ပြသသည်-

 #add '_total' as suffix to each column name
df = df. add_suffix (' _total ')

#view updated DataFrame
print (df)

   points_total assists_total rebounds_total blocks_total
0 25 5 11 6
1 12 7 8 6
2 15 7 10 3
3 14 9 6 2
4 19 12 6 7
5 23 9 5 9

နောက်ဆက်တွဲ “ _total” ကို ကော်လံအမည်များအားလုံးတွင် ထည့်ထားကြောင်း သတိပြုပါ။

မှတ်ချက် – ကော်လံအမည်များတွင် ရှေ့ဆက်ထည့်ရန်၊ ၎င်းအစား add_prefix ကို ရိုးရိုးရှင်းရှင်း အသုံးပြုပါ။

နည်းလမ်း 2- သီးခြားကော်လံအမည်များသို့ နောက်ဆက်တွဲတစ်ခု ထည့်ပါ။

အောက်ပါ ကုဒ်သည် အမှတ်များ နှင့် ကော်လံ များတွင်သာ “ _total” ၏ နောက်ဆက်တွဲကို မည်သို့ထည့်ရမည်ကို ပြသသည်-

 #specify columns to add suffix to
cols = [' points ', ' assists ']

#add _'total' as suffix to specific columns
df = df. rename (columns={c: c+' _total ' for c in df.columns if c in cols})

#view updated DataFrame
print (df)

   points_total assists_total rebounds blocks
0 25 5 11 6
1 12 7 8 6
2 15 7 10 3
3 14 9 6 2
4 19 12 6 7
5 23 9 5 9

‘_total’ နောက်ဆက်တွဲကို အမှတ်များ နှင့် ကော်လံများတွင် သာ ပေါင်းထည့်ထားကြောင်း သတိပြုပါ။

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

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

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

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

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