r/pythonhelp • • Nov 11 '22

How would I write python code for this

The 2010 US Census:

  1. Determine the size of the sheet (max_row and max_column)

  2. Count the total population in column (D)

  3. Count the number of census tracts in each state

Hint:

The following code may help in #3:

state_counter = {}

def addone(state):     if state in state_counter:           state_counter[state] += 1     else:           state_counter[state] = 1

0 Upvotes

4 comments sorted by

4

u/bulaybil Nov 12 '22

Yeah do your own homework.

2

u/CraigAT Nov 11 '22

There are Python modules to work with Excel or CSV files (you could export that sheet to a CSV file).

Once you are using those modules, working out those numbers should be trivial especially if you were able to come up with that final piece of code.

2

u/CraigAT Nov 11 '22

I'm not sure your final bit of code is the best way of counting the states, if I'm correct that requires going through the data set multiple times (once for each state)