[英]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 ![]() |
row\ nime\ Program one![]() |
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.