دنبال کننده ها

۱۳۹۶ اسفند ۱۱, جمعه

python - Handling mixed string with double qoutaions and numbers to save in csv

[ad_1]



I have three lines that I need to save as header of my csv files. They should look like this:



title = "dataset test"
variables = "X", "Y", "Z", "V"
zone t = "Data Field", i = 134, j = 293, k = 5, f=point


I am using the following code to create the pandas dataframe:



info = pd.DataFrame(['title = "dataset test"',
'variables = "X", "Y", "Z", "V"',
'zone t = "Data Field", i = 134, j = 293, k = 5, f=point'])


And using the following code to write the csv file:



with open(fpath, 'w') as myfile:
info.to_csv(myfile, header=None, index=False)


However the output in the csv file is as:



"title = ""dataset test"""
"variables = ""X"", ""Y"", ""Z"", ""V"""
"zone t = ""Data Field"", i = 134, j = 293, k = 5, f=point"



[ad_2]

لینک منبع