Changing numpy array to dataframe and merge two dataframe

Viewed 57

How I can change two numpy array and dataframe and merge them ?

I have:

X

array([1461, 1462, 1463, ..., 2917, 2918, 2919])

and

y_test_pred

array([272229.457876  , 256423.56032314, 281508.5907379 , ...,
       223281.89247352, 223185.78377167, 229313.97269616])

My goal is to make following format:

Id,SalePrice

1461,169000.1

1462,187724.1233

1463,175221

etc.

Many thanks,

Dataleon

1 Answers

Just construct a dataframe with concat:

df = pd.concat([pd.Series(X), pd.Series(y_test_pred)], axis=1).rename({0:  'Id', 1: 'SalePrice'}, axis=1)
Related