Selecting random rows (of data) from dataframe / csv file in Pyhton after designating start and end row...
up vote
0
down vote
favorite
Using the sample()
function I can get the random rows. Data set having 1000000
rows of data and I want to have a subset of 20000
rows. Importing random lines can be done through this solution
https://stackoverflow.com/a/22259008/8966221
reading a dataset
dataset = read_csv(file_path)
dataset_sub = dataset.sample(20000, random_state=1)
However I want to select random rows between row number 250000
to 750000
. Any possible solution in that regard?.
python random rows
add a comment |
up vote
0
down vote
favorite
Using the sample()
function I can get the random rows. Data set having 1000000
rows of data and I want to have a subset of 20000
rows. Importing random lines can be done through this solution
https://stackoverflow.com/a/22259008/8966221
reading a dataset
dataset = read_csv(file_path)
dataset_sub = dataset.sample(20000, random_state=1)
However I want to select random rows between row number 250000
to 750000
. Any possible solution in that regard?.
python random rows
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
Using the sample()
function I can get the random rows. Data set having 1000000
rows of data and I want to have a subset of 20000
rows. Importing random lines can be done through this solution
https://stackoverflow.com/a/22259008/8966221
reading a dataset
dataset = read_csv(file_path)
dataset_sub = dataset.sample(20000, random_state=1)
However I want to select random rows between row number 250000
to 750000
. Any possible solution in that regard?.
python random rows
Using the sample()
function I can get the random rows. Data set having 1000000
rows of data and I want to have a subset of 20000
rows. Importing random lines can be done through this solution
https://stackoverflow.com/a/22259008/8966221
reading a dataset
dataset = read_csv(file_path)
dataset_sub = dataset.sample(20000, random_state=1)
However I want to select random rows between row number 250000
to 750000
. Any possible solution in that regard?.
python random rows
python random rows
edited Nov 19 at 7:25
Md. Mokammal Hossen Farnan
585320
585320
asked Nov 19 at 6:55
Devarshi Mandal
14
14
add a comment |
add a comment |
3 Answers
3
active
oldest
votes
up vote
0
down vote
I think you need this:
dataset = read_csv(file_path)
dataset_sub = dataset.sample(random.randint(250000,750000), random_state=1)
Thanks for your reply, but I want to randomly extract only say 20,000 rows. I think that argument is also to be entered
– Devarshi Mandal
Nov 19 at 10:14
add a comment |
up vote
0
down vote
What you can do is to create a DataFrame containing the rows between row number 250000 to 750000, then select 20000 random rows from that.
dataset_sub = dataset.loc[250000:750000].sample(20000, random_state=1)
Thanks this is helpful
– Devarshi Mandal
Nov 19 at 10:16
add a comment |
up vote
0
down vote
I think the following code works:
import random
a=random.sample(range(250000,750000), 20000)
data=dataset.loc[a]
add a comment |
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
I think you need this:
dataset = read_csv(file_path)
dataset_sub = dataset.sample(random.randint(250000,750000), random_state=1)
Thanks for your reply, but I want to randomly extract only say 20,000 rows. I think that argument is also to be entered
– Devarshi Mandal
Nov 19 at 10:14
add a comment |
up vote
0
down vote
I think you need this:
dataset = read_csv(file_path)
dataset_sub = dataset.sample(random.randint(250000,750000), random_state=1)
Thanks for your reply, but I want to randomly extract only say 20,000 rows. I think that argument is also to be entered
– Devarshi Mandal
Nov 19 at 10:14
add a comment |
up vote
0
down vote
up vote
0
down vote
I think you need this:
dataset = read_csv(file_path)
dataset_sub = dataset.sample(random.randint(250000,750000), random_state=1)
I think you need this:
dataset = read_csv(file_path)
dataset_sub = dataset.sample(random.randint(250000,750000), random_state=1)
answered Nov 19 at 7:08
Rudolf Morkovskyi
714116
714116
Thanks for your reply, but I want to randomly extract only say 20,000 rows. I think that argument is also to be entered
– Devarshi Mandal
Nov 19 at 10:14
add a comment |
Thanks for your reply, but I want to randomly extract only say 20,000 rows. I think that argument is also to be entered
– Devarshi Mandal
Nov 19 at 10:14
Thanks for your reply, but I want to randomly extract only say 20,000 rows. I think that argument is also to be entered
– Devarshi Mandal
Nov 19 at 10:14
Thanks for your reply, but I want to randomly extract only say 20,000 rows. I think that argument is also to be entered
– Devarshi Mandal
Nov 19 at 10:14
add a comment |
up vote
0
down vote
What you can do is to create a DataFrame containing the rows between row number 250000 to 750000, then select 20000 random rows from that.
dataset_sub = dataset.loc[250000:750000].sample(20000, random_state=1)
Thanks this is helpful
– Devarshi Mandal
Nov 19 at 10:16
add a comment |
up vote
0
down vote
What you can do is to create a DataFrame containing the rows between row number 250000 to 750000, then select 20000 random rows from that.
dataset_sub = dataset.loc[250000:750000].sample(20000, random_state=1)
Thanks this is helpful
– Devarshi Mandal
Nov 19 at 10:16
add a comment |
up vote
0
down vote
up vote
0
down vote
What you can do is to create a DataFrame containing the rows between row number 250000 to 750000, then select 20000 random rows from that.
dataset_sub = dataset.loc[250000:750000].sample(20000, random_state=1)
What you can do is to create a DataFrame containing the rows between row number 250000 to 750000, then select 20000 random rows from that.
dataset_sub = dataset.loc[250000:750000].sample(20000, random_state=1)
answered Nov 19 at 7:10
Andreas
1,7761618
1,7761618
Thanks this is helpful
– Devarshi Mandal
Nov 19 at 10:16
add a comment |
Thanks this is helpful
– Devarshi Mandal
Nov 19 at 10:16
Thanks this is helpful
– Devarshi Mandal
Nov 19 at 10:16
Thanks this is helpful
– Devarshi Mandal
Nov 19 at 10:16
add a comment |
up vote
0
down vote
I think the following code works:
import random
a=random.sample(range(250000,750000), 20000)
data=dataset.loc[a]
add a comment |
up vote
0
down vote
I think the following code works:
import random
a=random.sample(range(250000,750000), 20000)
data=dataset.loc[a]
add a comment |
up vote
0
down vote
up vote
0
down vote
I think the following code works:
import random
a=random.sample(range(250000,750000), 20000)
data=dataset.loc[a]
I think the following code works:
import random
a=random.sample(range(250000,750000), 20000)
data=dataset.loc[a]
answered Nov 22 at 15:21
Enayat Rajabi
9731129
9731129
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53369669%2fselecting-random-rows-of-data-from-dataframe-csv-file-in-pyhton-after-design%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown