Reputation: 23
How to select remains of data frame after random selection of data?
This will give 80% data. but I want remaining 20% also.
df.sample(frac=0.8)
Upvotes: 2
Views: 1783
Reputation: 917
You can use:
df_sample = df.sample(frac=0.8)
and then:
df_remains = df[~df.index.isin(df_sample.index)]
Upvotes: 3
Reputation: 2073
Since you also have numpy
installed, a Pandas dependency, you can do something like this:
import numpy as np
p = .8
msk = np.random.rand(len(df)) < p
sample = df[msk]
remains = df[~msk]
Upvotes: 1