Pandas dataframe ၏ ပထမတန်းကို မည်သို့ရယူရမည်နည်း။
ပန်ဒါ DataFrame ၏ပထမအတန်းကိုရရှိရန် အောက်ပါနည်းလမ်းများကို သင်အသုံးပြုနိုင်ပါသည်။
နည်းလမ်း 1- DataFrame ၏ပထမတန်းကိုရယူပါ။
df. iloc [0]
နည်းလမ်း 2- သီးခြားကော်လံများအတွက် DataFrame ၏ ပထမဆုံးအတန်းကို ရယူပါ။
df[[' column1 ', ' column2 ']]. iloc [0]
အောက်ဖော်ပြပါနမူနာများသည် အောက်ပါ pandas 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
ဥပမာ 1- Pandas DataFrame ၏ ပထမတန်းကို ရယူပါ။
အောက်ပါ ကုဒ်သည် ပန်ဒါ DataFrame ၏ ပထမတန်းကို မည်သို့ရယူရမည်ကို ပြသသည် ။
#get first row of DataFrame df. iloc [0] points 25 assists 5 rebounds 11 Name: 0, dtype: int64
DataFrame ရှိ ကော်လံတစ်ခုစီ၏ ပထမအတန်းရှိ တန်ဖိုးများကို ပြန်ပေးကြောင်း သတိပြုပါ။
ဥပမာ 2- သီးခြားကော်လံများအတွက် Pandas DataFrame ၏ပထမတန်းကိုရယူပါ။
အောက်ဖော်ပြပါ ကုဒ်သည် အမှတ်များ နှင့် ကော်လံ များကိုသာ ရရှိရန်အတွက် ပန်ဒါ DataFrame ၏ ပထမအတန်း၏ တန်ဖိုးများကို မည်သို့ရယူရမည်ကို ပြသသည်-
#get first row of values for points and rebounds columns df[[' points ', ' rebounds ']]. iloc [0] points 25 rebounds 11 Name: 0, dtype: int64
အမှတ်များ နှင့် rebounds ကော်လံများအတွက် ပထမတန်းတန်ဖိုးများကို ပြန်ပေးကြောင်း သတိပြုပါ။
ထပ်လောင်းအရင်းအမြစ်များ
အောက်ဖော်ပြပါ သင်ခန်းစာများသည် ပန်ဒါများတွင် အခြားဘုံအလုပ်များကို မည်သို့လုပ်ဆောင်ရမည်ကို ရှင်းပြသည်-
Pandas DataFrame မှ ပထမဆုံး ကော်လံကို ဘယ်လိုရယူမလဲ။
Pandas DataFrame တွင် အတန်းများထည့်နည်း
Pandas DataFrame ရှိ အတန်းအရေအတွက်ကို ရေတွက်နည်း