How do quickly search through a .csv file in Python
Posted
by Baldur
on Stack Overflow
See other posts from Stack Overflow
or by Baldur
Published on 2010-02-19T20:51:01Z
Indexed on
2010/03/14
20:25 UTC
Read the original article
Hit count: 405
I'm reading a 6 million entry .csv file with Python, and I want to be able to search through this file for a particular entry.
Are there any tricks to search the entire file? Should you read the whole thing into a dictionary or should you perform a search every time? I tried loading it into a dictionary but that took ages so I'm currently searching through the whole file every time which seems wasteful.
Could I possibly utilize that the list is alphabetically ordered? (e.g. if the search word starts with "b" I only search from the line that includes the first word beginning with "b" to the line that includes the last word beginning with "b")
I'm using import csv.
(a side question: it is possible to make csv go to a specific line in the file? I want to make the program start at a random line)
Edit: I already have a copy of the list as an .sql file as well, how could I implement that into Python?
© Stack Overflow or respective owner