I am trying to generate .CSV file (or.txt). The script is simple. However, the generated *.CSV file is putting all values in one cell in each row. I want each value to be in separate cell. Kindly advise.
JavaScript
x
9
1
from tabulate import tabulate
2
nestedlist = [["Point 1",0,5,0],
3
["Point 2",0,0,0],
4
["Point 3",5,0,0],
5
["Point 4",5,5,0],]
6
7
with open('GCP.csv', 'w') as f:
8
f.write(tabulate(nestedlist, headers=['n','x','y','z'],tablefmt="plain"))
9
Advertisement
Answer
I suggest using pandas
:
JavaScript
1
9
1
import pandas as pd
2
nestedlist = [["Point 1",0,5,0],
3
["Point 2",0,0,0],
4
["Point 3",5,0,0],
5
["Point 4",5,5,0],]
6
7
df = pd.DataFrame(nestedlist, columns=['n','x','y','z'])
8
df.to_csv('GCP.csv', index=False)
9