0

I have a csv file over 100,000 lines of 1 column One column lastName
Smith
Willams
Smith David Smith Williams David

I need to count the number of times each name occurs and print the result

I have no code to show because I don't know if I should read into a list or a dictionary.

Any thoughts would be appreciated.

I want to read in the csv and count how many times

  • Read the csv as a list, store the counts as a dictionary – Rashid 'Lee' Ibrahim Mar 24 '20 at 18:48
  • SO I did that, read into a dictionary. There are more than 1 million rows in the csv, and python just hangs as it is doing it. So it's taking way too long. – James Turner Mar 24 '20 at 22:07
  • Well one million rows is a far cry from one hundred thousand... So keep the count dictionary, but instead of reading all the rows into a list. Do it a row at a time and process it as you go. That way only one row will ever be in memory at a time. See this answer for reference: https://stackoverflow.com/questions/17444679/reading-a-huge-csv-file – Rashid 'Lee' Ibrahim Mar 25 '20 at 00:50
  • 1
    This is a helpful answer. I'm sorry I am coming back to this so long after. I got away from Python for some time but as I revisit these questions I want to ensure that I acknowledge when the advice is/was helpful. – James Turner Jul 04 '22 at 00:40

0 Answers0