How do I create test and train samples from one dataframe with pandas?

Scikit Learn’s train_test_split is a good one. It will split both numpy arrays and dataframes.

from sklearn.model_selection import train_test_split

train, test = train_test_split(df, test_size=0.2)

Leave a Comment