Question

I need help Structuring data into certain dictionaries in Python to help answer a few questions....

I need help Structuring data into certain dictionaries in Python to help answer a few questions. I have a CSV file and i need help looping thru the data to get an output similar to this. where the keys are the region (for data_by_region) or country (for data_by_country) and the values are dictionaries where the years are the keys. Based on this information i need a few dictionaries one being called data_by_region and another called data_by_country. Her is a link to the CSV file if anyone can help:

https://docs.google.com/document/d/1v68_QQX7Tn96l-b0LMO9YZ4ZAn_KWDMUJboa6LEyPr8/edit?usp=sharing


"Western Africa" : {

2005: {
    "Population annual rate of increase (percent)": 2.6,
"Total fertility rate (children per women)": 6,
"Infant mortality for both sexes (per 1,000 live births)": 95.7,
"Life expectancy at birth for both sexes (years)": 49.3,
"Life expectancy at birth for males (years)": 48.4,
"Life expectancy at birth for females (years)": 50.2
},
2010: { 
    
    },
2015: {
    
0 0
Add a comment Improve this question Transcribed image text
Answer #1

If you have any doubts, please give me comment...

Code:

import csv

with open("data.csv") as csv_file:

data = {}

csv_reader = csv.reader(csv_file, delimiter=',')

l_c = 0

for row in csv_reader:

if(l_c==0):

l_c+=1

continue

row[2] = int(row[2])

if row[1] not in data:

data[row[1]] = {}

if row[2] not in data[row[1]]:

data[row[1]][row[2]] = {}

data[row[1]][row[2]][row[3]] = float(row[4].replace(",", ""))

print(data)

Add a comment
Know the answer?
Add Answer to:
I need help Structuring data into certain dictionaries in Python to help answer a few questions....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Hi, I need help with Python Dictionaries please. Question: Write a function named "add_key_value" that takes...

    Hi, I need help with Python Dictionaries please. Question: Write a function named "add_key_value" that takes a key-value store as a parameter with strings as keys and integers as values. The function will add a key-value pair to the input store with a key of "slam" and a value of 39. There is no need to return any value. Thanks!

  • Could anyone help add to my python code? I now need to calculate the mean and...

    Could anyone help add to my python code? I now need to calculate the mean and median. In this programming assignment you are to extend the program you wrote for Number Stats to determine the median and mode of the numbers read from the file. You are to create a program called numstat2.py that reads a series of integer numbers from a file and determines and displays the following: The name of the file. The sum of the numbers. The...

  • i read this story today and need help with few questions

    i read this story today and need help with few questions. sorry it a bit long. i actually not real understand it, especially ending. THE WHITE KNIGHTby Eric NicolOnce upon a time there was a knight who lived in a little castle on the edge of the forest of Life. One day this knight looked in the mirror and saw that he was a White Knight."Lo!" he cried. "I am the White Knight and therefore represent good. I am the...

  • I need help in these questions in 30 minutes, please answer them fast Question 17 Between...

    I need help in these questions in 30 minutes, please answer them fast Question 17 Between 25% and 33% of all returnees exit their firms in what period of time? One year Two years Three years Five years Question 18 Duplicating American competencies in foreign countries is called: Ethnocentrism Home replication strategy Local responsiveness Integration framework Question 19 When an upward price change causes no loss of demand, the price is said to be: Elastic Inelastic Question 20 Wal-Mart occasionally...

  • Unix questions, i need help on Hint: Commands to study to answer this question: predefined shell...

    Unix questions, i need help on Hint: Commands to study to answer this question: predefined shell variables, and .profile script file, echo SHELL, HOME, PATH, MAIL and TERM are predefined shell variables. You can use the value of a shell variable in a shell command putting $ in front of it. For example, to display the value of the HOME directory of the user, specify $HOME in the echo command like echo $HOME. Do not give just the value of...

  • I need help in C++ implementing binary search tree. I have the .h file for the...

    I need help in C++ implementing binary search tree. I have the .h file for the binary search tree class. I have 4 classic texts, and 2 different dictionaries. Classic Texts: Alice In Wonderland.txt A Tale of Two Cities.txt Pride And Prejudice.txt War and Peace.txt 2 different dictionaries: Dictionary.txt Dictionary-brit.txt The data structures from the standard template library can not be used.The main program should open the text file, read in the words, remove the punctuation and change all the...

  • 14. Select the number of participants in the Beck & Watson study Group of answer choices...

    14. Select the number of participants in the Beck & Watson study Group of answer choices 8 13 22 35 15. Beck & Watson determined their final sample size via Group of answer choices coding saturation triangulation ethnography 16.Through their study, Beck & Watson determined Group of answer choices after a traumatic birth, subsequent births have no troubling effects after a traumatic birth, subsequent births brought fear, terror, anxiety, and dread Subsequent Childbirth After a Previous Traumatic Birth Beck, Cheryl...

  • I need help on the highlighted questiona. For questions 2,4, & 5 I need help with...

    I need help on the highlighted questiona. For questions 2,4, & 5 I need help with the step by step process to the answers. Thanks! what financial data do you need? i sent a photo of the assigment. The last photo is of a balance sheet and income statement QUESTIONS 1. Give as many reasons as you can why Moore's initial estimate of the value of the restaurant was inappropriate. 2. Calculate the current liquidation value of the business assuming...

  • Help, I need everyone's answer. [LO 5.2] Case 5.3 Procedure Codes Find the correct procedure codes...

    Help, I need everyone's answer. [LO 5.2] Case 5.3 Procedure Codes Find the correct procedure codes for the following: 1. Insertion, LeVeen shunt. 2. Ms. Silvers is referred to Dr. Valentine for chest pain. The patient's encounter form on her second appointment shows a cardiovascular stress test using submaximal treadmill, with continuous electrocardiographic monitor- ing, with physician supervision, interpretation, and report. Find the procedure code for the procedure cardio- vascular stress test. (Hint: Look under the heading “Cardiology.") 3. Patient...

  • 10. The Beck & Watson article is a Group of answer choices quantitative study qualitative study...

    10. The Beck & Watson article is a Group of answer choices quantitative study qualitative study 11. Beck & Watson examined participants' experiences and perceptions using what type of research design? Group of answer choices particpant obersvation phenomenology 12. Select the participants in the Beck & Watson study Group of answer choices Caucasian women with 2-4 children Caucasian pregnant women 13. In the Beck & Watson study, data was collected via a(n) Group of answer choices internet study focus group...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT