pandas concat error: cannot concatenate a non-NDFrame object

这一生的挚爱 提交于 2020-01-06 07:55:30

问题


I have two data frames and I am just writing a simple pd.concat to append the data vertically:

    SRC_OF_PAYMENT_80_00_CY= 
    pd.concat(['src_of_payment_cy','src_of_payment_df'],axis=0, ignore_index=True)

Both are dataframes types. So I don't understand the error: TypeError: cannot concatenate a non-NDFrame object

Here is the out for df.info() for both:
<class 'pandas.core.frame.DataFrame'>
Int64Index: 10 entries, 0 to 9
Data columns (total 3 columns):
Type_of_cost    10 non-null object
Total_NHE       10 non-null float64
year            10 non-null int64
dtypes: float64(1), int64(1), object(1)
memory usage: 320.0+ bytes
src_of_payment_cy

<class 'pandas.core.frame.DataFrame'>
Int64Index: 18 entries, 9 to 26
Data columns (total 3 columns):
Type_of_cost    18 non-null object
Total_NHE       18 non-null int64
year            18 non-null int64
dtypes: int64(2), object(1)
memory usage: 576.0+ bytes
src_of_payment_df 

回答1:


Remove the apostrophes around the dataframe names like -

SRC_OF_PAYMENT_80_00_CY= 
    pd.concat([src_of_payment_cy,src_of_payment_df],axis=0, ignore_index=True)


来源:https://stackoverflow.com/questions/54871885/pandas-concat-error-cannot-concatenate-a-non-ndframe-object

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!