Challenge: Append Data into a CSV file

Can we write a code that will append data to a CSV file?

Problem statement

Append the data into a CSV file and view the appended file using the cat command to view data inside it.

Given data

A Test.csv file with the following data.

"Name","City"
"Prateek","New Delhi"
"Daniel","New York"

Expected output

The following Test.csv file after appending the data into it.

"Name","City"
"Prateek","New Delhi"
"Daniel","New York"
"Michel","London"

Coding exercise

This problem is designed to check your understanding, so you are encouraged to solve it on your own. If you get completely stuck, refer to the next lesson which will explain the solution in detail.

Python

Hint: Use the writerow function of the writer to append the data.

Note: Use the /usercode/Test.csv path to access the Test.csv file.

Note: Run the cat Test.csv command after hitting the run button to see the expected Test.csv file.

Get hands-on with 1200+ tech skills courses.