gpt-4o-2024-08-06· OpenAI
WildChat-4.8M (AI2)
python skip first 10000 rows when reading search123 =…
- User
python
skip first 10000 rows when reading
search123 = pd.read_csv('all_search_queries_2309_cats.csv.gz', nrows=15000000, usecols=[ 'query' ])
- Assistant
To skip the first 10,000 rows when reading a CSV file using pandas, you can use the
skiprowsparameter in thepd.read_csvfunction. Here's how you can modify your code to achieve that:pythonimport pandas as pd # Read the CSV file, skipping the first 10,000 rows search123 = pd.read_csv( 'all_search_queries_2309_cats.csv.gz', skiprows=10000, # Skip the first 10,000 rows nrows=15000000, # Read up to 15,000,000 rows starting from the 10,001st row usecols=['query'] # Only use the column 'query' )This code will start reading at the 10,001st row due to
skiprows=10000, and it will read up to 15,000,000 rows from that point onward. Make sure to adjust thenrowsparameter if you need a different number of rows after skipping.