Error specifying filename in to_csv FileNotFoundError

Asked 2 years ago, Updated 2 years ago, 44 views

I want to output the data frame to csv, but to_csv does not work.
When I try to print a data frame called result with the following code, I get an error.

code:

result.to_csv('directory/filename.csv', encoding='shift-jis')

error messages:

FileNotFoundError: [Errno2] No such file or directory: 'Directory/File Name.csv'

You can also read csv in the same directory with the pd.read_csv command, or you can try the directory name to_csv as ./".
Why can't I print to a folder that should be there?

python python3 pandas

2022-09-30 21:40

1 Answers

By Python specification,

result.to_csv('directory/filename.csv', encoding='shift-jis')

not

result.to_csv('directory name\\filename.csv', encoding='shift-jis')`

That's right. It's a common mistake.
The escape sequence here will be helpful.


2022-09-30 21:40

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.