How to create a train and test sample from one dataframe using pandas?

0 votes
I have a large dataset in the form of dataframe, which I want to split into training and testing sample of 80% and 20% respectively. How can I do it?
Jul 3 in Python by Shabnam
• 920 points
32 views

1 answer to this question.

0 votes

Hi,

The below written code can help you to split your dataset into training and testing samples:

from sklearn.model_selection import train_test_split
trainingSet, testSet = train_test_split(df, test_size=0.2)

Test size may differ depending on the percentage of data you want to put in your testing and training samples

answered Jul 3 by Taj
• 1,040 points

Related Questions In Python

0 votes
1 answer

How to create and read from a temporary file in Python?

Hi, there is a very simple solution ...READ MORE

answered Jan 29 in Python by Nymeria
• 3,520 points
45 views
0 votes
1 answer

How to create Pandas dataframe from Python list?

You can do it like this: import ...READ MORE

answered Apr 5 in Python by Likhita
44 views
0 votes
1 answer
+2 votes
2 answers

How can I replace values with 'none' in a dataframe using pandas

Actually in later versions of pandas this ...READ MORE

answered Aug 13, 2018 in Python by bug_seeker
• 15,350 points
4,917 views
0 votes
1 answer

How to rename columns in pandas (Python)?

It is easy by just adding ".columns" ...READ MORE

answered Apr 30, 2018 in Data Analytics by DeepCoder786
• 1,700 points
88 views
0 votes
1 answer

What is the Difference in Size and Count in pandas (python)?

The major difference is size includes NaN ...READ MORE

answered Apr 30, 2018 in Data Analytics by DeepCoder786
• 1,700 points
679 views
0 votes
2 answers
0 votes
1 answer

Converting a pandas data-frame to a dictionary

Emp_dict=Employee.to_dict('records') You can directly use the 'to_dict()' function ...READ MORE

answered May 23, 2018 in Data Analytics by Bharani
• 4,550 points
1,179 views
0 votes
1 answer

Is there a way to store a huge dataset as a dataframe using Pandas?

This can be easliy done by using ...READ MORE

answered Jun 21 in Python by Taj
• 1,040 points
17 views
0 votes
1 answer

How to iterate over row in a Dataframe in Pandas?

Hi, You can use df.iterrows(), it yields both ...READ MORE

answered Jul 18 in Python by Taj
• 1,040 points
19 views