Reputation: 61
I tried to include 3 lists into dictionary, convert to data frame and then write to csv
dicti = {'X': list_X, 'Y': list_Y, 'Z': list_Z}
df2 = pd.DataFrame(dicti)
df2.to_csv('dataa.csv')
Output printed in csv
"9.0, 9.0, 2.5, 1.5811388300841898, 1.2","10.0, 10.0, 2.5, 1.5811388300841898, 1.2","18.0, 18.0, 2.5, 1.5811388300841898, 1.2"
Expected output
9.0, 9.0, 2.5, 1.5811388300841898, 1.2,10.0, 10.0, 2.5, 1.5811388300841898, 1.2,18.0, 18.0, 2.5, 1.5811388300841898, 1.2
Upvotes: 0
Views: 2185
Reputation: 61
While writing into csv, following code can be used in order to remove double quotes.
This parameter is an inbuit feature of df.to_csv()
df.to_csv('data2.csv',index=False,header= False,sep = ',', quoting = csv.QUOTE_NONE, escapechar = ' ')
It worked for me and Hope this helps
Upvotes: 3
Reputation: 24
I believe the work you are doing here to populate list_X:
list_X.append(str(calculateFeatures(dfx_temp)).strip('[]'))
is actually resulting in a list that contains one string, which looks like this.
list_X = ['9.0, 9.0, 2.5, 1.5811388300841898, 1.2']
It looks a lot like a list of numbers, but it isn't.
What are the dimensions of your resulting df? If your lists each contain one string, the dimensions would be [1 rows x 3 columns].
Upvotes: -1