user3222184
user3222184

Reputation: 1111

Switch Axis of Pandas Data frame

If we used 100 observations in the training dataset to fit the model, then the index of the next time step for making a prediction would be specified to the prediction function as start=101, end=101. This would return an array with one element containing the prediction.

We also would prefer the forecasted values to be in the original scale, in case we performed any differencing (d>0 when configuring the model). This can be specified by setting the typ argument to the value ‘levels’: typ=’levels’.

Alternately, we can avoid all of these specifications by using the forecast() function, which performs a one-step forecast using the model.

We can split the training dataset into train and test sets, use the train set to fit the model, and generate a prediction for each element on the test set.

Upvotes: 1

Views: 670

Answers (1)

jezrael
jezrael

Reputation: 863226

I think you need select column, transpose by T with rename_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  

If need transpose all columns:

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  

Upvotes: 2

Related Questions