pandas read csv random rows

Solutions on MaxInterview for pandas read csv random rows by the best coders in the world

we are a community of more than 2 million smartest coders
registration for
employee referral programs
are now open
get referred to google, amazon, flipkart and more
register now
  
pinned-register now
showing results for - "pandas read csv random rows"
Victoria
28 Jun 2020
1import pandas as pd
2import numpy as np
3
4filename = 'hugedatafile.csv'
5nlinesfile = 10000000
6nlinesrandomsample = 10000
7lines2skip = np.random.choice(np.arange(1,nlinesfile+1), (nlinesfile-nlinesrandomsample), replace=False)
8df = pd.read_csv(filename, skiprows=lines2skip)