r/pythonhelp • u/Latter-Disaster-7828 • Nov 11 '22
How would I write python code for this
The 2010 US Census:
We have a spreadsheet file censuspopdata.xlsxLinks to an external site.
There is just one sheet in the censuspopdata.xlsx Links to an external site.spreadsheet, named 'Population by Census Tract', and each row holds the data for a single census tract.
The columns are the tract number (A), the state abbreviation (B), the county name (C), and the population of the tract (D).
Write a program that will do the following:
Determine the size of the sheet (max_row and max_column)
Count the total population in column (D)
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
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)
4
u/bulaybil Nov 12 '22
Yeah do your own homework.