Skip to content Skip to sidebar Skip to footer

Reading And Writing Data In Csv Files In Python

I am new to Python and I am having some problems with CSV files in Python. Please help me out How do I open and read csv files in Python which are present in some other directory?

Solution 1:

First argument of open() is file, which can be an absolute path like C:\Program Files\file.csv or a relative one like ../../file.csv here .. refers to the directory above the current directory and . refers to the current directory.

import csv
withopen('../path/to/file.csv', 'w') as f:
    csv_writer = csv.writer(f)
    csv_writer.writerows(your_row_data)

Where your_row_data is a list of lists.

Post a Comment for "Reading And Writing Data In Csv Files In Python"