1

I'm trying to use pandas.DataFrame.to_csv to export a DataFrame to a .csv file, however after running the following code there's no output:

collist = sve2_all.columns
path_d = 'C:\\Users\\Desktop\\From EPD'
sve2_all.to_csv('sve2_all', path = path_d, columns = collist)

Docs

2
  • What if you leave out the columns=collist argument? (not necessary as you are writing all columns). Furthermore, the path kwarg is not in the docs you linked to. Commented Apr 11, 2014 at 10:03
  • 1
    What happens when you do the following: sve2_all.to_csv(path_d + '\\sve2_all.csv') Commented Apr 11, 2014 at 10:05

1 Answer 1

4

I think what you are doing won't work as the path is not being used to set the destination path and resulting csv

This should work:

import os
path_d = 'C:\\Users\\Desktop\\From EPD'
sve2_all.to_csv(os.path.join(path_d, 'sve2_all.csv'))

Also, you are passing a string as the first parameter to to_csv which is probably confusing it also as it should be a fully qualified path or buffer for path_or_buf parameter.

Sign up to request clarification or add additional context in comments.

2 Comments

Indeed, path is not a kwarg of to_csv (but it apparantly does not give an error on this, but is just ignored)
@joris yes that is worrying, it would be nice that this raised an error but not sure how given python's flexibility

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.