【问题标题】:Switch Axis of Pandas Data frame切换熊猫数据框的轴
【发布时间】:2017-11-08 09:41:55
【问题描述】:

如果我们在训练数据集中使用 100 个观测值来拟合模型,那么进行预测的下一个时间步的索引将指定给预测函数,即 start=101,end=101。这将返回一个数组,其中一个元素包含预测。

我们还希望预测值采用原始比例,以防我们执行任何差分(配置模型时 d>0)。这可以通过将 typ 参数设置为值“levels”来指定:typ='levels'。

或者,我们可以通过使用 forecast() 函数来避免所有这些规范,该函数使用模型执行一步预测。

我们可以将训练数据集拆分为训练集和测试集,使用训练集拟合模型,并为测试集上的每个元素生成预测。

【问题讨论】:

    标签: python pandas


    【解决方案1】:

    我认为您需要选择列,将Trename_axis 转置:

    df = df[['NA_Sales']].T.rename_axis(None, axis=1)
    print (df)
              Action  Adventure  Fighting    Misc  Platform  Puzzle  Racing  \
    NA_Sales  871.96     105.46    221.99  410.02    446.26  123.78  359.09   
    
              Role-Playing  Shooter  Simulation  Sports  Strategy  
    NA_Sales        325.89   575.16      183.31  678.78     68.59  
    

    如果需要转置所有列:

    df = df.T.rename_axis(None, axis=1)
    print (df)
                   Action  Adventure  Fighting    Misc  Platform  Puzzle  Racing  \
    NA_Sales       871.96     105.46    221.99  410.02    446.26  123.78  359.09   
    EU_Sales       518.64      63.74    100.17  215.89    200.76   50.78  237.25   
    JP_Sales       154.15      51.10     86.71  106.95    130.66   57.31   56.68   
    Other_Sales    185.55      16.70     36.22   75.29     51.28   12.55   77.08   
    Global_Sales  1731.26     237.23    445.05  808.79    829.30  244.95  730.40   
    
                  Role-Playing  Shooter  Simulation   Sports  Strategy  
    NA_Sales            325.89   575.16      183.31   678.78     68.59  
    EU_Sales            186.77   305.57      113.29   369.49     45.02  
    JP_Sales            348.64    37.67       63.40   134.59     49.41  
    Other_Sales          59.17   100.27       31.52   133.05     11.32  
    Global_Sales        920.57  1019.15      391.81  1316.33    174.62  
    

    【讨论】:

    • 我只希望流派水平显示。并且销售额垂直显示
    • 你能添加想要的输出吗?
    • 我改答案了,请查收。
    猜你喜欢
    • 1970-01-01
    • 2022-12-05
    • 2017-04-08
    • 2020-06-19
    • 2015-08-11
    • 1970-01-01
    • 2017-02-22
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多