Pandas dataframe တွင် အတန်းများထည့်နည်း (ဥပမာများဖြင့်)


pandas DataFrame အဆုံးတွင် စာကြောင်းတစ်ခုထည့်ရန် df.loc() လုပ်ဆောင်ချက်ကို သင်အသုံးပြုနိုင်သည်-

 #add row to end of DataFrame
df. loc [ len (df. index )] = [value1, value2, value3, ...]

df.append() လုပ်ဆောင်ချက်ကို လက်ရှိ DataFrame မှ အခြား DataFrame အဆုံးအထိ လိုင်းများစွာကို ပေါင်းထည့်နိုင်သည်-

 #append rows of df2 to end of existing DataFrame
df = df. append (df2, ignore_index = True )

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

ဥပမာ 1- Pandas DataFrame သို့ အတန်းတစ်ခုထည့်ပါ။

အောက်ပါ ကုဒ်သည် ပန်ဒါ DataFrame ၏အဆုံးတွင် စာကြောင်းတစ်ကြောင်းထည့်နည်းကို ပြသသည်-

 import pandas as pd

#createDataFrame
df = pd. DataFrame ({' points ': [10, 12, 12, 14, 13, 18],
                   ' rebounds ': [7, 7, 8, 13, 7, 4],
                   ' assists ': [11, 8, 10, 6, 6, 5]})

#view DataFrame
df

	points rebound assists
0 10 7 11
1 12 7 8
2 12 8 10
3 14 13 6
4 13 7 6
5 18 4 5

#add new row to end of DataFrame
df. loc [ len (df. index )] = [20, 7, 5]

#view updated DataFrame
df

        points rebound assists
0 10 7 11
1 12 7 8
2 12 8 10
3 14 13 6
4 13 7 6
5 18 4 5
6 20 7 5

ဥပမာ 2- Pandas DataFrame တွင် အတန်းများစွာကို ထည့်ပါ။

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

 import pandas as pd

#createDataFrame
df = pd. DataFrame ({' points ': [10, 12, 12, 14, 13, 18],
                   ' rebounds ': [7, 7, 8, 13, 7, 4],
                   ' assists ': [11, 8, 10, 6, 6, 5]})

#view DataFrame
df

	points rebound assists
0 10 7 11
1 12 7 8
2 12 8 10
3 14 13 6
4 13 7 6
5 18 4 5

#define second DataFrame
df2 = pd. DataFrame ({' points ': [21, 25, 26],
                    ' rebounds ': [7, 7, 13],
                    ' assists ': [11, 3, 3]})

#add new row to end of DataFrame
df = df. append (df2, ignore_index = True )

#view updated DataFrame
df

        points rebound assists
0 10 7 11
1 12 7 8
2 12 8 10
3 14 13 6
4 13 7 6
5 18 4 5
6 21 7 11
7 25 7 3
8 26 13 3

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

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

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

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

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