I have a csv file generated from mathematica, it look like this:
with open('sample.csv','r') as f:
scsv =f.read()
print(scsv)
yields
"{-955.1999999999999, 1.5568236482421087, -0.03326937763412006}","{-955.1999999999999, 1.5568572873672764, -0.026663002665836356}","{-955.1999999999999, 1.5568909480671234, -0.01847982437149327}"
"{-950.4, 1.5568236482421087, -0.016625954967908727}","{-950.4, 1.5568572873672764, -0.001015311835489717}","{-950.4, 1.5568909480671234, 0.006326172704000158}"
"{-945.5999999999999, 1.5568236482421087, -0.04292903732414247}","{-945.5999999999999, 1.5568572873672764, -0.01602757944255171}","{-945.5999999999999, 1.5568909480671234, -0.014847744429619007}
I want to turn it into python list to get a 3D plot and this is my try:
try:
# for Python 2.x
from StringIO import StringIO
except ImportError:
# for Python 3.x
from io import StringIO
import csv
with open('sample.csv','r') as f:
scsv =f.read()
g = StringIO(scsv)
reader = csv.reader(g,delimiter=',')
your_list = list(reader)
for row in reader:
print('\t'.join(row))
print(your_list)
This code yields:
[['{-955.1999999999999, 1.5568236482421087, -0.03326937763412006}', '{-955.1999999999999, 1.5568572873672764, -0.026663002665836356}', '{-955.1999999999999, 1.5568909480671234, -0.01847982437149327}'], ['{-950.4, 1.5568236482421087, -0.016625954967908727}', '{-950.4, 1.5568572873672764, -0.001015311835489717}', '{-950.4, 1.5568909480671234, 0.006326172704000158}'], ['{-945.5999999999999, 1.5568236482421087, -0.04292903732414247}', '{-945.5999999999999, 1.5568572873672764, -0.01602757944255171}', '{-945.5999999999999, 1.5568909480671234, -0.014847744429619007}']]
I don't know how to improve it, help! :)