Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Is this code right for the question? If not how can I improve it? 5 import csv 7 with open(freqs.tsv, r) as finput: 8 with

Is this code right for the question? If not how can I improve it? image text in transcribed
image text in transcribed
5 import csv 7 with open("freqs.tsv", "r") as finput: 8 with open("freqs_mean.tsv", " as foutput: writer reader csv.writer(foutput) csv. reader(finput) 10 12 for row in reader: 13 rowsrow.split() 14 Sum0 15 for i in range (1,len (rows)): 16 17 lf ( row [i] "\t"); = sum += 0 18 else: 19 sum float (row[i]) 20 21 22 23 24 row.append (str (sum/len (rows)-1)) writer.wrirerow(row) TSV Practice Attached Files: freqs.tsv (153.937 KB) File freqs tsv (attached) contains frequencies of 2.300+ words and expressions used by adolescents and young adults engaged in a certain unhealthy activity. The fle has no header row. The columns are delimited by tabs. The first column of the file lists the words, the remaining columns list frequencies as floating point numbers (some columns have missing values designated as empty strings) Write a program that shall add another column to the table. The values in the new column shall be equal to the average (mean) value of the frequencies in each row treat the missing values as 0). The new table shall be saved into the file fregs-mean.tsy in the same format as the original file (tab-separated, no header row, missing values designated as empty strings). Example: Original row eating di sorder Processed row eating disorder You must use module csv for reading and writing the files. 1.2406 1.14931.8994 1.3713 1.2406 1.1493 1.8994 1.3713 0,8086

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David Kroenke

4th Edition

0136086535, 9780136086536

More Books

Students also viewed these Databases questions