0

I am fairly new to python.

I want to read a csv file and store the content of as tuples. This is my code so far, however I can't figure out how to make the tuples:

 import csv
 with open('apple_finance.csv', 'r') as csv_file:
 apple_reader = csv.reader(csv_file)

 with open('new_apple_finance.csv', 'w', newline='') as new_file:
     csv_writer = csv.writer(new_file, delimiter=',')

     for line in apple_reader:
         csv_writer.writerow(line)

Can someone help me?

Thank you.

TML
  • 37
  • 2
  • 6
  • `list(df.itertuples(index=False, name=None))`. This should be good enough – bigbounty Oct 27 '19 at 14:36
  • Welcome to the site! Curious what is your goal with the data - does this have to be tuples? [check this out](https://stackoverflow.com/questions/18776370/converting-a-csv-file-into-a-list-of-tuples-with-python) – Jimmy Smith Oct 27 '19 at 14:38

1 Answers1

0

You can map the sequence of lists generated by csv.reader as tuples:

list_of_tuples = list(map(tuple, csv.reader(csv_file)))
blhsing
  • 91,368
  • 6
  • 71
  • 106