ပြင်နည်း- သင်သည် အရာဝတ္ထုနှင့် int64 ကော်လံများကို ပေါင်းစည်းရန် ကြိုးစားနေပါသည်။
ပန်ဒါများကို အသုံးပြုရာတွင် သင်ကြုံတွေ့ရနိုင်သည့် အမှားတစ်ခုမှာ-
ValueError : You are trying to merge on int64 and object columns.
If you wish to proceed you should use pd.concat
Pandas DataFrames နှစ်ခုကို ပေါင်းစည်းရန် သင်ကြိုးစားသောအခါတွင် ဤအမှားသည် သင်ပေါင်းစည်းနေသောကော်လံသည် DataFrame တစ်ခုရှိ အရာဝတ္ထုတစ်ခုနှင့် အခြား DataFrame ရှိ ကိန်းပြည့်တစ်ခုဖြစ်သည်။
အောက်ဖော်ပြပါ ဥပမာသည် ဤအမှားကို လက်တွေ့တွင် မည်သို့ပြုပြင်ရမည်ကို ပြသထားသည်။
အမှားကို ဘယ်လိုပြန်ထုတ်မလဲ။
အောက်ဖော်ပြပါ ပန်ဒါဝက်ဝံ DataFrames နှစ်ခုကို ဖန်တီးတယ်ဆိုပါစို့။
import pandas as pd #createDataFrame df1 = pd. DataFrame ({' year ': [2015, 2016, 2017, 2018, 2019, 2020, 2021], ' sales ': [500, 534, 564, 671, 700, 840, 810]}) df2 = pd. DataFrame ({' year ': ['2015', '2016', '2017', '2018', '2019', '2020', '2021'], ' refunds ': [31, 36, 40, 40, 43, 70, 62]}) #view DataFrames print (df1) year sales 0 2015 500 1 2016 534 2 2017 564 3 2018 671 4 2019 700 5,2020 840 6 2021 810 print (df2) year refunds 0 2015 31 1 2016 36 2 2017 40 3 2018 40 4 2019 43 5 2020 70 6 2021 62
ယခု ကျွန်ုပ်တို့သည် DataFrames နှစ်ခုကို ပေါင်းစည်းရန် ကြိုးစားသည်ဆိုပါစို့။
#attempt to merge two DataFrames
big_df = df1. merge (df2, on=' year ', how=' left ')
ValueError : You are trying to merge on int64 and object columns.
If you wish to proceed you should use pd.concat
ပထမ DataFrame တွင်ပြောင်းလဲနိုင်သော နှစ်သည် ကိန်း ပြည့်ဖြစ်သော်လည်း၊ ဒုတိယ DataFrame ရှိ နှစ် ပြောင်းလဲနိုင်သောနှစ်သည် အရာဝတ္ထုဖြစ်သောကြောင့်ဖြစ်သည်။
အမှားကိုဘယ်လိုပြင်မလဲ။
ဤအမှားကို ပြင်ရန် အလွယ်ဆုံးနည်းလမ်းမှာ ဒုတိယ DataFrame ၏ နှစ် variable ကို ကိန်းပြည့်အဖြစ်သို့ ပြောင်းပြီးနောက် ပေါင်းစည်းခြင်း ပြုလုပ်ရန်ဖြစ်သည်။
အောက်ပါ syntax သည် ၎င်းကို မည်သို့လုပ်ဆောင်ရမည်ကို ပြသသည်-
#convert year variable in df2 to integer
df2[' year ']=df2[' year ']. astype (int)
#merge two DataFrames
big_df = df1. merge (df2, on=' year ', how=' left ')
#view merged DataFrame
big_df
year sales refunds
0 2015 500 31
1 2016 534 36
2 2017 564 40
3 2018 671 40
4 2019 700 43
5 2020 840 70
6 2021 810 62
ValueError တစ်စုံတစ်ရာမရရှိကြောင်း မှတ်သားထားပြီး DataFrames နှစ်ခုကို တစ်ခုတည်းအဖြစ် အောင်မြင်စွာ ပေါင်းစပ်နိုင်စေရန် စီမံထားပါသည်။
ထပ်လောင်းအရင်းအမြစ်များ
အောက်ဖော်ပြပါ သင်ခန်းစာများသည် Python ရှိ အခြားသော ဘုံအမှားများကို မည်သို့ပြင်ဆင်ရမည်ကို ရှင်းပြသည်-
ပြုပြင်နည်း- ကော်လံများ ထပ်နေသော်လည်း နောက်ဆက်တွဲကို သတ်မှတ်မထားပါ။
ပြုပြင်နည်း- Object ‘numpy.ndarray’ တွင် ‘append’ attribute မရှိပါ။
ပြင်ဆင်နည်း- scalar တန်ဖိုးများအားလုံးကို အသုံးပြုပါက၊ အညွှန်းတစ်ခုကို ကျော်သွားရန်လိုအပ်သည်။