2 回答
TA贡献2019条经验 获得超9个赞
如果我可以假设您y_test是numpy array.
您可以使用以下内容:
predict_length = 3
y_test = np.reshape(np.array([5,6,7,3,2,1]), (2,3))
df = pd.DataFrame(y_test, columns=['predicition{}'.format(x+1) for x in range(predict_length)])
print(df)
predicition1 predicition2 predicition3
0 5 6 7
1 3 2 1
如果你的python版本>=3.6,我们可以使用 f-strings
predict_length = 3
y_test = np.reshape(np.array([5,6,7,3,2,1]), (2,3))
df = pd.DataFrame(y_test, columns=[f'predicition{x+1}' for x in range(predict_length)])
print(df)
predicition1 predicition2 predicition3
0 5 6 7
1 3 2 1
TA贡献1865条经验 获得超7个赞
这会有所帮助
# a simple function to do the column name creation
column_print = lambda col_len : ['prediction' + str(i+1) for i in range(col_len)]
y_test = [5,6,7],[3,2,1]
y_test = np.array(y_test) # convert y_test to a numpy array so you can use the shape
#method
size_y = y_test.shape
resultTestDataset = pd.DataFrame(y_test, columns=column_print(size_y[1]))
print(resultTestDataset)
添加回答
举报