ပြင်နည်း- ပထမအငြင်းအခုံသည် ပန်ဒါအရာဝတ္တု၏ ထပ်တလဲလဲဖြစ်ရမည်၊ သင်သည် “dataframe” အမျိုးအစား အရာဝတ္ထုတစ်ခုကို ကျော်သွားသည်;
Python ကိုအသုံးပြုရာတွင် သင်ကြုံတွေ့ရလေ့ရှိသော အမှားတစ်ခုမှာ-
TypeError: first argument must be an iterable of pandas objects, you passed an object
of type "DataFrame"
DataFrame အမည်များကို ကွင်းအတွင်းမထည့်ဘဲ ပန်ဒါနှစ်ခု DataFrame နှစ်ခုကို ပေါင်းထည့်ရန် concat() လုပ်ဆောင်ချက်ကို အသုံးပြုသောအခါတွင် ဤအမှားသည် များသောအားဖြင့် ဖြစ်ပေါ်ပါသည်။
အောက်ဖော်ပြပါ ဥပမာသည် ဤအမှားကို လက်တွေ့ဖြေရှင်းနည်းကို ပြသထားသည်။
အမှားကို ဘယ်လိုပြန်ထုတ်မလဲ။
ကျွန်ုပ်တို့တွင် အောက်ပါ Panda DataFrames နှစ်ခုရှိသည်ဟု ယူဆကြပါစို့။
import pandas as pd #create first DataFrame df1 = pd. DataFrame ({' x ': [25, 14, 16, 27, 20,15, 14], ' y ': [5, 7, 7, 5, 7, 6, 9], ' z ': [8, 8, 10, 6, 6, 9, 6]}) print (df1) X Y Z 0 25 5 8 1 14 7 8 2 16 7 10 3 27 5 6 4 20 7 6 5 15 6 9 6 14 9 6 #create second DataFrame df2 = pd. DataFrame ({' x ': [58, 60, 65], ' y ': [14, 22, 23], ' z ': [9, 12, 19]}) print (df2) X Y Z 0 58 14 9 1 60 22 12 2 65 23 19
ယခု ကျွန်ုပ်တို့သည် DataFrame နှစ်ခုကို DataFrame တစ်ခုထဲသို့ထည့်ရန် concat() function ကိုအသုံးပြုရန်ကြိုးစားသည်ဆိုပါစို့။
#attempt to add two DataFrames together
combined = pd. concat (df1, df2, ignore_index= True )
#view final DataFrame
print (combined)
TypeError: first argument must be an iterable of pandas objects, you passed an object
of type "DataFrame"
concat() လုပ်ဆောင်ချက်ရှိ ကွင်းကွင်းအတွင်း DataFrame အမည်များကို ထည့်သွင်းရန် ပျက်ကွက်ခဲ့ခြင်းကြောင့် ကျွန်ုပ်တို့သည် အမှားအယွင်းတစ်ခု လက်ခံရရှိနေပါသည်။
အမှားကိုဘယ်လိုပြင်မလဲ။
ဤအမှားကိုဖြေရှင်းရန်နည်းလမ်းမှာ အောက်ပါအတိုင်း concat() လုပ်ဆောင်ချက်ရှိ စတုရန်းကွင်းပိတ်များတွင် DataFrame အမည်များကို ရိုးရှင်းစွာထည့်သွင်းရန်ဖြစ်သည်-
#append two DataFrames together
combined = pd. concat ([df1, df2], ignore_index= True )
#view final DataFrame
print (combined)
X Y Z
0 25 5 8
1 14 7 8
2 16 7 10
3 27 5 6
4 20 7 6
5 15 6 9
6 14 9 6
7 58 14 9
8 60 22 12
9 65 23 19
ယခုတစ်ကြိမ်တွင် အမှားအယွင်းမရှိဘဲ DataFrames နှစ်ခုကို အောင်မြင်စွာ ပေါင်းစပ်နိုင်သည်ကို သတိပြုပါ။
ထပ်လောင်းအရင်းအမြစ်များ
အောက်ဖော်ပြပါ သင်ခန်းစာများသည် Python ရှိ အခြားသော ဘုံအမှားများကို မည်သို့ပြင်ဆင်ရမည်ကို ရှင်းပြသည်-
Python တွင် ပြင်နည်း- Object ‘numpy.ndarray’ ကို ခေါ်ဆို၍မရပါ။
ပြုပြင်နည်း- TypeError- Object ‘numpy.float64’ ကို ခေါ်ဆို၍မရပါ။
ပြင်နည်း- အမှားအမျိုးအစား- မျှော်လင့်ထားသော စာကြောင်း သို့မဟုတ် ဘိုက်အရာဝတ္ထု