Pandas dataframe ၏ ပထမကော်လံကို မည်သို့ရယူရမည်နည်း။


Pandas DataFrame ၏ ပထမကော်လံကို ရယူရန် အောက်ပါ syntax ကို သင်အသုံးပြုနိုင်ပါသည်။

 df. iloc [:, 0]

ရလဒ်ကတော့ ပန်ဒါတွေ ဆက်တိုက်ပါပဲ။ ရလဒ်ကို pandas DataFrame ဖြစ်လိုပါက၊ အောက်ပါ syntax ကို အသုံးပြုနိုင်ပါသည်။

 df. iloc [:, :1]

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

ဥပမာ 1- 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
print (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

#get first column
first_col = df. iloc [:, 0]

#view first column
print (first_col)

0 25
1 12
2 15
3 14
4 19
5 23
6 25
7 29
Name: points, dtype: int64

ရလဒ်မှာ ပန်ဒါအတွဲလိုက်၊

 #check type of first_col
print ( type (first_col))

<class 'pandas.core.series.Series'>

ဥပမာ 2- Pandas DataFrame ၏ပထမကော်လံကိုရယူပါ (DataFrame ကိုပြန်ယူပါ)

အောက်ဖော်ပြပါ ကုဒ်သည် ပန်ဒါဒေတာဘောင်၏ ပထမကော်လံကို မည်သို့ရယူရမည်ကို ပြသပြီး DataFrame ကို လျော်ညီစွာ ပြန်ပို့ပေးသည်-

 #get first column (and return a DataFrame)
first_col = df. iloc [:, :1]

#view first column
print (first_col)

   points
0 25
1 12
2 15
3 14
4 19
5 23
6 25
7 29

#check type of first_col
print ( type (first_col))

<class 'pandas.core.frame.DataFrame'>

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

Pandas DataFrame တွင် ကော်လံတစ်ခုထည့်နည်း
Pandas DataFrame တွင် ကော်လံတစ်ခု ထည့်သွင်းနည်း
Pandas ရှိ အခြေအနေတစ်ခုအပေါ် အခြေခံ၍ ကော်လံအသစ်တစ်ခု ဖန်တီးနည်း

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

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