【问题标题】:pandas concat error: cannot concatenate a non-NDFrame objectpandas concat 错误:无法连接非 NDFrame 对象
【发布时间】:2019-02-25 17:45:02
【问题描述】:

我有两个数据框,我只是在写一个简单的 pd.concat 来垂直追加数据:

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

两者都是数据帧类型。所以我不明白错误: TypeError: 无法连接非 NDFrame 对象

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 

【问题讨论】:

  • 我觉得好傻!谢谢!

标签: python pandas dataframe concat


【解决方案1】:

删除数据框名称周围的撇号,例如 -

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

【讨论】:

    猜你喜欢
    • 2017-12-23
    • 2017-08-15
    • 2014-08-19
    • 2016-08-10
    • 2017-05-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-09
    • 1970-01-01
    相关资源
    最近更新 更多