Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

python csv

import csv

with open('data.csv', 'r') as f:
    reader = csv.reader(f)
    # loop through each row and print each value
    for row in reader:
        for e in row:
            print(e)

with open('data.csv', 'r') as f:
    # change the delimiter from the default comma to another delimiter
    reader = csv.reader(f, delimiter="|")

    for row in reader:

        for e in row:
            print(e)

nums = [[1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12]]

with open('numbers2.csv', 'w') as f:
    writer = csv.writer(f)
    # write arrays as rows to CSV file
    for row in nums:
        writer.writerow(row)


with open('numbers2.csv', 'w') as f:

    writer = csv.writer(f, delimiter="+")
    # write arrays as row to CSV file with + as the delimiter instead of commas
    for row in nums:
        writer.writerow(row)
Source by codefreelance.net #
 
PREVIOUS NEXT
Tagged: #python #csv
ADD COMMENT
Topic
Name
5+3 =