Skip to content
Advertisement

How to print random n rows from a csv file?

So i have a big csv file and my code prints all the rows but i want to print, for example, only 20 random rows from 100000 rows. I know that somehow with random.sample u can do that, but i don’t really know how. Any suggestions?

There is my code:

JavaScript

Advertisement

Answer

I assume you want to randomly sample your data, rather than just take the first 20 rows?

In this case you can convert data to a list and then sample it:

JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement