Pandas dataframe တွင် အညွှန်းအမည်ပြောင်းနည်း
Pandas DataFrame ၏ အညွှန်းကော်လံကို အမည်ပြောင်းရန် အောက်ပါ syntax ကို အသုံးပြုနိုင်ပါသည်။
df. index . rename (' new_index_name ', inplace= True )
အောက်ဖော်ပြပါ ဥပမာသည် ဤ syntax ကို လက်တွေ့တွင် မည်သို့အသုံးပြုရမည်ကို ပြသထားသည်။
ဥပမာ- Pandas DataFrame တွင် အညွှန်းအမည်ပြောင်းပါ။
ကျွန်ုပ်တို့တွင် အောက်ပါ ပန်ဒါ DataFrame ရှိသည် ဆိုပါစို့။
import pandas as pd #createDataFrame df = pd. DataFrame ({' 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]}) #view DataFrame df points assists rebounds 0 25 5 11 1 12 7 8 2 15 7 10 3 14 9 6 4 19 12 6 5 23 9 5 6 25 9 9 7 29 4 12
လောလောဆယ် DataFrame တွင် အညွှန်းအမည် မရှိပါ။
#display index name print ( df.index.name ) None
အညွှန်းအမည်ပြောင်းရန် df.index.rename() ကို အသုံးပြုနိုင်ပါသည်။
#rename index df. index . rename (' new_index ', inplace= True ) #view updated DataFrame df points assists rebounds new_index 0 25 5 11 1 12 7 8 2 15 7 10 3 14 9 6 4 19 12 6 5 23 9 5 6 25 9 9 7 29 4 12
inplace=True သည် မူလ DataFrame ဂုဏ်သတ္တိများအားလုံးကို ထိန်းသိမ်းထားရန် ပန်ဒါများကို ပြောပြသည်ကို သတိပြုပါ။
ယခု DataFrame တွင် အညွှန်းအမည်တစ်ခု ရှိနေကြောင်း အတည်ပြုနိုင်သည်-
#display index name print ( df.index.name ) new_index
ထပ်လောင်းအရင်းအမြစ်များ
အောက်ဖော်ပြပါ သင်ခန်းစာများသည် ပန်ဒါများတွင် အခြားဘုံလုပ်ဆောင်ချက်များကို မည်သို့လုပ်ဆောင်ရမည်ကို ရှင်းပြသည်-
Pandas DataFrame တွင် ကော်လံတစ်ခုထည့်နည်း
Pandas DataFrame မှ ပထမဆုံး ကော်လံကို ဘယ်လိုရယူမလဲ။