# data splitting into 3 sets based on years

let's suppose we have a customer data from the year 2015 to 2019, I want to train_test_split() my data such that my data gets divided into three sets, set-1 is from 2015 to 2017 (3 years) on which i will train my model, set-2 i.e. 2018(1 year) on which i will validate my model , set 3 is 2019(1 year) on which I will test my model. I want a code to divide data into 3 sets based on time(years).

• Welcome to DS StackExchange. Please elaborate more on the question. What are you asking exactly? As of now, it's not possible to help you. Jan 16, 2020 at 15:36
• Hello, let's suppose we have a customer data from the year 2015 to 2019, I want to train_test_split() my data such that my data gets divided into three sets, set-1 is from 2015 to 2017 (3 years) on which i will train my model, set-2 i.e. 2018(1 year) on which i will validate my model , set 3 is 2019(1 year) on which I will test my model. I want a code to divide data into 3 sets based on time(years). Jan 16, 2020 at 16:21
• Thank you! Please update the main question with this information Jan 16, 2020 at 16:24
• Do you realize that this is a terrible idea from a machine learning perspective? The year is very likely a significant factor and you are removing 2 years completely from the learning process. Jan 16, 2020 at 21:10

train_df = data[data['year'].isin(['2015', '2016', '2017'])