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, 2019 in Python by Shabnam
• 920 points
770 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, 2019 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, 2019 in Python by Nymeria
• 3,520 points
125 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, 2019 in Python by Likhita
136 views
0 votes
1 answer

How to have values from a List1 into Columns Names and List 2 Values as Index for an Empty DataFrame

Try like this, it will give you ...READ MORE

answered Jul 10, 2019 in Python by Cherukuri
• 32,440 points
76 views
0 votes
1 answer

How do I create a dataframe using a dictionary in pandas?

Hi @Hannah, You need to define your dictionary ...READ MORE

answered Nov 18, 2019 in Python by Eric
57 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,720 points
180 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,720 points
813 views
0 votes
2 answers

Replacing a row in pandas data.frame

key error. I love python READ MORE

answered Feb 18, 2019 in Data Analytics by anonymous
3,255 views
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,560 points
2,087 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, 2019 in Python by Taj
• 1,040 points
50 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, 2019 in Python by Taj
• 1,040 points
305 views