Originally I had a list of list and each list contains tuples of strings (from some computations). I want to save them for later, so I don't have to do all the computations again and just read the csv.
L = [l1,l2,...]
l1 = [('a','b'), ('c','d'),...]
l2 = [('e','f'), ('g','h'),...]...
I converted it to a pandas data frame:
import pandas as pd
df = pd.DataFrame(L)
df.to_csv('MyLists.csv', sep=";")
So each list l is saved as a row in the csv. Some time later I want to use the list saved in the csv again. So I imported pandas again and did:
readdf = pd.read_csv('MyLists.csv', delimiter = ";")
newList = readdf.values.tolist()
The problem is that every tuple is a string itself now, i.e. every list in newList looks as follows:
l1 = ['('a','b')', '('c', 'd')',...]
When I look at the csv with a text editor, it looks correct, somehow like:
('a','b');('c','d');...
I tried to read it directly with:
import csv
newList = []
with open('MyLists.csv') as f:
reader = csv.reader(f, delimiter=";")
for row in reader:
newList.append(row)
But the problem is the same. So how can I get rid of the extra " ' "?