Home > front end >  Export result to csv and print it in one column
Export result to csv and print it in one column

Time:12-08

I have the following code, where I predict if it is going to rain the next day. As result I get 1 or 0.

weatherbayes = GaussianNB()
weatherbayes.fit(X_train, y_train)
predbayes = weatherbayes.predict(df_test)
data = [predbayes]
print(data)
np.savetxt("student.csv",data, newline =" ", delimiter = '\t',  fmt ='% s')

I get following result: enter image description here

data shape: (1, 11540)

But I need to print it in one column and for each value a row.

CodePudding user response:

If your shape is (1, 11540) and you want one value per row, transpose your array.

# data = np.random.choice([0, 1], (1, 10))
# data.shape -> (1, 10)
np.savetxt('student.csv', data.T, fmt='%d')

Content of student.csv file:

0
1
0
1
0
1
1
1
1
0
  • Related