1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Keith_Richards [23]
2 years ago
12

Read_data Define a function named read_data with two parameters. The first parameter will be a csv reader object (e.g., the valu

e returned when calling the function csv.reader) and the second parameter will be a list of strings representing the keys for this data. The list matches the order of data in the file, so the second parameter's first entry is the key to use for data in the file's first column, the second parameter's second entry is the key to use for data in the file's second column, and so on. The function's first parameter will be a csv reader object and not a string. This means you do not need the with..as nor create the csv reader in your function, but this will be done in the code calling your function. For example, to execute read_data using a file named "smallDataFileWithoutHeaders.csv" you would write the following code: with open("smallDataFileWithoutHeaders.csv") as f_in: csv_r = csv.reader(f_in) result = read_data(csv_r,['tow_date','tow_reason']) You would then want to include code to check that header had the expected value. The function should return a list of dictionaries. This list will contain a dictionary for each row read using the first parameter. The keys of these dictionaries will be the entries in the second parameter and the values will be the data read in from the file (you can assume there will be equal numbers list entries and columns).
For example, suppose the lines of the file being read by csv_r were:

2015-12-30,IL

2018-04-07,GA

then the call read_data(csv_r,['tow_date','tow_reason']) would need to return:

[{'tow_date': '2015-12-30', 'tow_reason': 'IL'},
{'tow_date': '2018-04-07', 'tow_reason': 'GA'}]

Computers and Technology
1 answer:
Sav [38]2 years ago
8 0

Answer:

Check the explanation

Explanation:

Given below is the code for the question. PLEASE MAKE SURE INDENTATION IS EXACTLY AS SHOWN IN IMAGE.

import csv

def read_data(csv_r, keys):

  data = []

  for row in csv_r:

      mydict = {}

      for i in range(len(keys)):

          mydict[keys[i]] = row[i]

      data.append(mydict)

  return data

SCREENSHOT:

You might be interested in
Select four tasks associated with operating system maintenance. Cleaning inside the computer Defragmenting the hard drive Deleti
hram777 [196]

Answer:

Cleaning inside the computer

Defragmenting the hard drive

Deleting temporary files

Organizing data

Explanation:

7 0
2 years ago
President Roosevelt's Fireside Chats were:
larisa86 [58]
C. Entertaining radio shows that families listened to in the evening. He did these chats to inform the public on what he was going to do about the problems facing the public.
3 0
2 years ago
Read 2 more answers
QUESTION 1
slava [35]
Answer is Bit defender Internet security
B
6 0
2 years ago
What can be designed to create annoying glitches or destroy data
Yanka [14]
Viruses can cause this.
3 0
3 years ago
Which tools is used to bundle cables neatly inside and outside of a computer?​
Ugo [173]

Answer:

Cable Ties

Explanation:

6 0
3 years ago
Other questions:
  • Which button, when pressed, allows light from the subject to fall on the sensor?
    8·1 answer
  • The __________ tag is used to create a forced line break without starting a new paragraph.
    13·1 answer
  • Which type of computer graphic can be blown up to a much larger size without getting distorted or losing quality?
    5·1 answer
  • Which of the following pathways is related to Agriculture, Food, and Natural Resources?
    14·1 answer
  • Does anyone know what to do when brainly won't let you answer questions? I click on answer question and then it just sits there
    15·2 answers
  • I need help I have questions I need answers in coding html,css,js and python.Fast
    7·1 answer
  • Hi who plays among us
    9·1 answer
  • Your computer is taking longer than usual to open files and you notice that your hard drive light stays on longer than usual whi
    9·1 answer
  • Office 365 ProPlus can be deployed to your enterprise. When doing so, which tool enables you to choose the language, hardware ar
    5·1 answer
  • Priortization is an example of a skill that helps you reach long term goals because
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!