Multiple pandas dataframes (ဥပမာနှင့်အတူ) ထည့်နည်း
ပန်ဒါ DataFrames အများအပြားကို တစ်ပြိုင်နက် ထည့်သွင်းရန် အောက်ပါ အခြေခံ syntax ကို သင်အသုံးပြုနိုင်သည်-
import pandas as pd #append multiple DataFrames df_big = pd. concat ([df1,df2, df3], ignore_index= True )
ဤအထူးအစီအမံသည် df1 ၊ df2 နှင့် df3 တို့ကို df_big ဟုခေါ်သော ပန်ဒါဒေတာဘောင်တစ်ခုထဲသို့ ပေါင်းထည့်မည်ဖြစ်သည်။
အောက်ဖော်ပြပါ ဥပမာသည် ဤ syntax ကို လက်တွေ့တွင် မည်သို့အသုံးပြုရမည်ကို ပြသထားသည်။
ဥပမာ 1- Pandas DataFrames များစွာကို တစ်ပြိုင်နက် ထည့်ပါ။
အောက်ဖော်ပြပါ ကုဒ်သည် ပန်ဒါမျိုးစုံ DataFrames ကို တစ်ပြိုင်နက် ထည့်သွင်းနည်းကို ပြသသည်-
import pandas as pd #create three DataFrames df1 = pd. DataFrame ({'player': ['A', 'B', 'C', 'D', 'E'], 'points':[12, 5, 13, 17, 27]}) df2 = pd. DataFrame ({'player': ['F', 'G', 'H', 'I', 'J'], 'points':[24, 26, 27, 27, 12]}) df3 = pd. DataFrame ({'player': ['K', 'L', 'M', 'N', 'O'], 'points':[9, 5, 5, 13, 17]}) #append all DataFrames into one DataFrame df_big = pd. concat ([df1,df2, df3], ignore_index= True ) #view resulting DataFrame print (df_big) player points 0 to 12 1 B 5 2 C 13 3 D 17 4 E 27 5 F 24 6 G 26 7:27 a.m. 8 I 27 9 D 12 10K 9 11 L 5 12 M 5 13 N 13 14 O 17
ရလဒ်သည် DataFrames သုံးခုတစ်ခုစီမှ အတန်းအားလုံးပါဝင်သည့် ကြီးမားသော DataFrame တစ်ခုဖြစ်သည်။
ignore_index=True argument သည် DataFrame တစ်ခုစီရှိ မူရင်းအညွှန်းကိန်းများကို လျစ်လျူရှုရန် ပန်ဒါများကို ပြောထားပြီး DataFrame အသစ်အတွက် 0 မှ စတင်သည့် အညွှန်းအသစ်တစ်ခုကို ဖန်တီးပါ။
ဥပမာအားဖြင့်၊ ကျွန်ုပ်တို့သည် ignore_index=အောက်ပါ DataFrames နှစ်ခုကို ထပ်စည်းထားသောအခါတွင် ကျွန်ုပ်တို့သည် ignore_index=True ကို အသုံးမပြုသောအခါ ဘာဖြစ်မည်ကို သုံးသပ်ပါ။
import pandas as pd #create two DataFrames with indices df1 = pd. DataFrame ({'player': ['A', 'B', 'C', 'D', 'E'], 'points':[12, 5, 13, 17, 27]}, index=[0, 1, 2, 3, 4]) df2 = pd. DataFrame ({'player': ['F', 'G', 'H', 'I', 'J'], 'points':[24, 26, 27, 27, 12]}, index=[2, 4, 5, 6, 9]) #stack the two DataFrames together df_big = pd. concat ([df1,df2]) #view resulting DataFrame print (df_big) player points 0 to 12 1 B 5 2 C 13 3 D 17 4 E 27 2 F 24 4G 26 5:27 a.m. 6 I 27 9 D 12
ရလဒ် DataFrame သည် DataFrames နှစ်ခုလုံးမှ ၎င်း၏မူလအညွှန်းတန်ဖိုးများကို ဆက်လက်ထိန်းသိမ်းထားသည်။
ယေဘူယျအားဖြင့်၊ သင်သည် မူရင်းအညွှန်းတန်ဖိုးများကို ထိန်းသိမ်းရန် တိကျသောအကြောင်းပြချက်မရှိပါက DataFrames အများအပြားကို ပေါင်းထည့်သည့်အခါ ignore_index=True ကို အသုံးပြုသင့်သည်။
ထပ်လောင်းအရင်းအမြစ်များ
Pandas DataFrame တွင် အလွတ်ကော်လံတစ်ခု ထည့်နည်း
Pandas DataFrame တွင် ကော်လံတစ်ခု ထည့်သွင်းနည်း
Pandas DataFrame ကို Excel သို့ဘယ်လိုထုတ်မလဲ။