【问题标题】:Pandas concatenate two dataframesPandas 连接两个数据帧
【发布时间】:2020-09-02 11:16:18
【问题描述】:

我有以下来自线性回归器和决策树回归器的训练分数。

lin_rmse_scores = np.array([65000.67382615, 70960.56056304, 67122.63935124, 66089.63153865,
 68402.54686442, 65266.34735288, 65218.78174481, 68525.46981754,
 72739.87555996, 68957.34111906])
tree_rmse_scores = np.array([65312.86044031, 70581.69865676, 67849.75809965, 71460.33789358,
 74035.29744574, 65562.42978503, 67964.10942543, 69102.89388457,
 66876.66473025, 69735.84760006])

我想使用 Pandas describe() 比较两个回归器的一些统计数据。对于线性回归器,我这样做如下:

df = pd.Series(lin_rmse_scores).describe()

对于我想指定列“Lin Regr”的系列。我想为决策树回归器附加第二列。结果应如下所示:

        'Lin Regr'          'Dec Tree'
count       10.000000        10.000000
mean     67828.386774       68848.189796
std       2601.596761        2719.219956
min      65000.673826       65312.860440
25%      65472.168399       67119.938073
50%      67762.593108       68533.501655
75%      68849.373294       70370.235893
max      72739.875560       74035.297446

【问题讨论】:

    标签: pandas numpy append


    【解决方案1】:

    让它们在describe之前合并

    s=pd.DataFrame({'lin_rmse_scores':lin_rmse_scores,'tree_rmse_scores':tree_rmse_scores}).describe()
           lin_rmse_scores  tree_rmse_scores
    count        10.000000         10.000000
    mean      67828.386774      68848.189796
    std        2601.596761       2719.219956
    min       65000.673826      65312.860440
    25%       65472.168399      67119.938073
    50%       67762.593108      68533.501655
    75%       68849.373294      70370.235893
    max       72739.875560      74035.297446
    

    【讨论】:

      猜你喜欢
      • 2020-04-07
      • 1970-01-01
      • 1970-01-01
      • 2017-11-02
      • 2016-09-16
      • 2019-06-27
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多