Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Set File_Path for to_csv() in Pandas

funded=r'C:\Users\hill\Desktop\wheels\Leads(1).csv'
funded= read_csv(funded)
funded=DataFrame(funded)
path='C:\Users\hvill\Destop\ '
funded.to_csv(path,'greenl.csv')

I want to have a variable that I can set the path in to_csv to. I tried path_or_buf = path. That doesn't work either.

like image 329
Jase Villam Avatar asked Apr 04 '14 21:04

Jase Villam


2 Answers

You need to either escape your back slashes or better use a raw string:

path='C:\\Users\\hvill\\Destop\\'

or better as fewer characters:

path=r'C:\Users\hvill\Destop\'

I also think you want to do this when saving:

funded.to_csv(path+'greenl.csv')

To avoid the ambiguity and allow portability of your code you can use this:

import os
funded.to_csv(os.path.join(path,r'green1.csv'))

this will append your csv name to your destination path correctly

like image 186
EdChum Avatar answered Oct 20 '22 10:10

EdChum


It may just be the case that you missed the k out of desktop

like image 28
M.Stones Avatar answered Oct 20 '22 12:10

M.Stones