Skip to content
Advertisement

How to get rid of the row numbers, to_csv?

after predicting the target value for the classification problem trying to get the predicted values in a .csv file along with the id of particular data instance but getting the unnecessary row numbers.

x_train,x_test,y_train,y_test = train_test_split(x,y, random_state=101,strtify =y)

cls = DecisionTreeClassifier()
cls.fit(x_train,y_train)

pred = cls.predict(x_test)
prediction = pd.DataFrame({'id':x_test['id'],'target':pred})
prediction.to_csv("path/prediction.csv")

x_test.head() image

to.csv() image

Advertisement

Answer

You index=False , doc specifies this argument

prediction.to_csv("path/prediction.csv",index=False)
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement