Skip to content

Instantly share code, notes, and snippets.

@ranpelta
Last active July 18, 2020 06:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ranpelta/cf1b0cf219a49f93e58942d525494f45 to your computer and use it in GitHub Desktop.
Save ranpelta/cf1b0cf219a49f93e58942d525494f45 to your computer and use it in GitHub Desktop.
test_size = int(len(df) * 0.1) # the test data will be 10% (0.1) of the entire data
train = df.iloc[:-test_size,:].copy()
# the copy() here is important, it will prevent us from getting: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_index,col_indexer] = value instead
test = df.iloc[-test_size:,:].copy()
print(train.shape, test.shape)
>>> ((28916, 4), (3212, 4))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment