-
-
Save toyeiei/e49d1f95ebfe0c28e8f1fc1f6ed63ba6 to your computer and use it in GitHub Desktop.
Case Study - US Births Analysis Function
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# write function for this analysis | |
def calculate_stat(data, k, v): | |
""" | |
input: data, idx key, idx value | |
output: dictionary with key: value pair | |
""" | |
result = {} | |
for row in data: | |
key = row.split(",")[k] | |
value = int(row.split(",")[v]) | |
if key in result: | |
result[key] += value | |
else: | |
result[key] = value | |
return result |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment