Home > Back-end >  Saving artificial sklearn data as an excel file
Saving artificial sklearn data as an excel file

Time:03-04

I am very new to Python and trying to save, as an Excel file, the dataset generated by the following code:

from sklearn.datasets import make_classification
import pandas as pd

X, y = make_classification(random_state=0)

Any help would be most appreciated!

CodePudding user response:

Use numpy to concatenate X and y then create your dataframe:

from sklearn.datasets import make_classification
import pandas as pd
import numpy as np

X, y = make_classification(random_state=0)
df = pd.DataFrame(np.concatenate([X, np.vstack(y)], axis=1))
df.to_excel('output.xlsx', index=False)
  • Related