A python function opens file data.csv, reads the data from the file and spits the data into three columns, x, y and z. The data is then printed out. Function: f = open("data.csv ", "r") print('x\ty\tz'.format()) for row in f:     temp = row.split(',')     for cell in temp:         print(cell,end='\t')     print()   data.csv contains: 1.2,2.1,1.1 2.3,3.2,0.6 0.7,1.9,0.1 1.8,2.5,0.3 4.6,2.7,0.9

C++ for Engineers and Scientists
4th Edition
ISBN:9781133187844
Author:Bronson, Gary J.
Publisher:Bronson, Gary J.
Chapter8: I/o Streams And Data Files
Section8.3: Random File Access
Problem 6E
icon
Related questions
Question

A python function opens file data.csv, reads the data from the file and spits the data into three columns, x, y and z. The data is then printed out.

Function:

f = open("data.csv ", "r")

print('x\ty\tz'.format())

for row in f:

    temp = row.split(',')

    for cell in temp:

        print(cell,end='\t')

    print()

 

data.csv contains:

1.2,2.1,1.1

2.3,3.2,0.6

0.7,1.9,0.1

1.8,2.5,0.3

4.6,2.7,0.9

Write a function write_csv_file that will compute the square of each of these values
and write out a new file called output.txt that contains the new data. Ensure that both
the input and output data have the same format (i.e. both are comma separated variable files)
and that the output numbers are written to 3 decimal places. Verify that the output is correct
by read csv file to read in the data, and print the new data out.
Transcribed Image Text:Write a function write_csv_file that will compute the square of each of these values and write out a new file called output.txt that contains the new data. Ensure that both the input and output data have the same format (i.e. both are comma separated variable files) and that the output numbers are written to 3 decimal places. Verify that the output is correct by read csv file to read in the data, and print the new data out.
Expert Solution
steps

Step by step

Solved in 4 steps with 4 images

Blurred answer
Knowledge Booster
File Input and Output Operations
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
C++ for Engineers and Scientists
C++ for Engineers and Scientists
Computer Science
ISBN:
9781133187844
Author:
Bronson, Gary J.
Publisher:
Course Technology Ptr