简体   繁体   English

在 python 中分隔“\”之前的所有值 - 扫描字符串文字时 EOL

[英]Separating all values before “\” in python - EOL while scanning string literal

I have a column named "path" in a dataframe with values that look like this:我在 dataframe 中有一个名为“path”的列,其值如下所示:

ind工业 path小路
0 0 row\ nime\ Program one行\尼姆\程序一
1 1 space\ Lib \ Books \ The Final count down空间\图书馆\书籍\最后倒计时

I want to be able to take the Path column, and select only the last word after the forward slash.我希望能够取 Path 列,而 select 只是正斜杠后的最后一个词。 ie row\ nime\ Program one would be just Program one行\ nime\ 程序一将只是程序一

Every code I write gives me EOL while scanning string literal.我写的每个代码在扫描字符串文字时都会给我 EOL。 take for instance举个例子

df[Final path]= df["Path"].split("\")

you have to use df[Final path]= df["Path"].split("\\")你必须使用df[Final path]= df["Path"].split("\\")
read more about it 阅读更多关于它的信息

you need to escape your \你需要逃避你的\

s ='row\ nime\ Program one'
print(s.split('\\')[-1]) # --> Program one

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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