pandas read csv random rows

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

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)