Apr-10-2024, 03:52 AM
(This post was last modified: Apr-10-2024, 03:52 AM by natalie321.)
I'm working on a Python script to parse a large CSV file and extract specific data, but I'm encountering performance issues. Here's a simplified version of my code:
The problem is that
build now gg
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
import csv def extract_data(csv_file): with open (csv_file, 'r' ) as file : reader = csv.reader( file ) next (reader) # Skip header row for row in reader: # Extracting data from specific columns data = row[ 1 ], row[ 3 ], row[ 5 ] process_data(data) def process_data(data): # Some processing on the extracted data print (data) csv_file = 'large_file.csv' extract_data(csv_file) |
large_file.csv
contains millions of rows, and my script is taking too long to process. I've tried optimizing the code, but it's still not efficient enough. Can someone suggest more efficient ways to parse and extract data from such a large CSV file in Python? Any help would be appreciated!build now gg