简体   繁体   中英

How to save a dataframe as a csv file with '/' in the file name

I want to save a dataframe to a .csv file with the name '123/123' , but it will split it in to two strings if I just type like df.to_csv('123/123.csv') .

Anyone knows how to keep the slash in the name of the file?

You can't use a slash in the name of the file. But you can use Unicode character that looks like slash if your file system support it http://www.fileformat.info/info/unicode/char/2215/index.htm

... "/" is used for indicating a path to a child folder, so your filename says the file 123.csv is in a folder "123"

however, that does not make it entirely impossible, just very difficult see this question:

https://superuser.com/questions/187469/how-would-i-go-about-creating-a-filename-with-invalid-characters-such-as

and that a charmap can find a character that looks like it, which is legal. In this case a division character

You can not use any of these chars in the file name ; /:*?\\"|

You can use a similar unicode character as the "Fraction slash - Unicode hexadecimal: 0x2044"

Example:

df.to_csv("123{0}123".format(u'\u2044'.encode('utf-8')))

It gives you the filename that you asked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM