122k views
0 votes
define a function named cache_load with one parameter. this parameter will be the name of a csv file (a string). you will need to load the contents of that file. the first line of the file contains the column headers and the rest of the file contains the data. for example, suppose the file sample.csv contains:

User Dhamo
by
6.0k points

1 Answer

6 votes

Answer:

Step-by-step explanation:

The following code is written in Python, it uses the CSV import to load and read the file that is passed as an argument to the function and then prints out all the information in that CSV. First, printing out the column names, and then printing out each individual row.

import csv

def read_csv_file(file):

with open(file) as csv_file:

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

line_count = 0

for row in csv_reader:

if line_count == 0:

print(f'Column names are: {", ".join(row)}')

line_count += 1

else:

print(f'\t{row[0]} {row[1]} {row[2]}.')

line_count += 1

print(f'There are a total of {line_count} lines.')

define a function named cache_load with one parameter. this parameter will be the-example-1
User Joe Koker
by
6.4k points