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?
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.
© 2025 OneMinuteCode. All rights reserved.