Skip to content
Advertisement

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

I have a fairly large dataset in the form of a dataframe and I was wondering how I would be able to split the dataframe into two random samples (80% and 20%) for training and testing.

Thanks!

Advertisement

Answer

I would just use numpy’s randn:

JavaScript

And just to see this has worked:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement