【问题标题】:When joined two Data Frames of same shape (480,6) with different columns, it created shape (175000,12)当用不同的列连接两个相同形状(480,6)的数据框时,它创建了形状(175000,12)
【发布时间】:2020-03-18 10:16:52
【问题描述】:

我无法放置整个数据框,因为它看起来很笨拙,所以我添加了 数据类型。

DF1 Columns:

    Dependents            object
    ApplicantIncome        int64
    CoapplicantIncome    float64
    LoanAmount           float64
    Loan_Amount_Term     float64
    Credit_History       float64

DF2 Columns:

    Gender            int64
    Married           int64
    Education         int64
    Self_Employed     int64
    Credit_History    int64
    Property_Area     int64

我的意图是将两个数据框并排放置并使其成为 单个数据框形状(480,12),但我得到更多行 整列重复数据。

【问题讨论】:

标签: python pandas dataframe


【解决方案1】:

我认为您正在寻找类似DF1.join(DF2) 的东西,但您应该准备一个输入和输出示例。另外,您可以使用pd.concat([DF1, DF2], axis=1)

【讨论】:

    【解决方案2】:

    IIUC,

    您需要 pandas concat 并传递 axis=1 这将使数据帧并排连接(垂直而不是水平)。代码应该如下:

    final_df = pd.concat([df_1, df_2], axis=1)

    【讨论】:

      猜你喜欢
      • 2017-10-31
      • 2021-03-28
      • 2019-10-02
      • 1970-01-01
      • 2021-12-11
      • 2019-01-20
      • 1970-01-01
      • 1970-01-01
      • 2023-04-10
      相关资源
      最近更新 更多