datafraeme中的带状路径熊猫
我在pandas中有此数据框,
path variable
0 /home/opt/chat A
1 /home/test B
2 /home/opt/projects C
3 /home/opt/projects/ex/remove/results D
如何将列路径剥离以在我的数据框架中返回此输出?
path variable
0 chat A
1 test B
2 projects C
3 results D
I have this dataframe in pandas
path variable
0 /home/opt/chat A
1 /home/test B
2 /home/opt/projects C
3 /home/opt/projects/ex/remove/results D
How do I strip the column path to return this output in my dataframe?
path variable
0 chat A
1 test B
2 projects C
3 results D
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以使用“ nofollow noreferrer”> /a>带有
n = 1
,以限制为一个拆分:或者,也许更好,
str.STR.STR.EXTRACT
带有简短的正则
([^/]+$)
[^/]+
,就在行结束之前$
):输出:
You can use
rsplit
withn=1
, to limit to one split:or, maybe better,
str.extract
with a short regex([^/]+$)
(any series of non-/
characters[^/]+
, just before the end of line$
):output:
使用
series.str。 Split
wth通过索引选择最后一个值:Use
Series.str.split
wth select last value by indexing: