[英]how to split column using python
My input is as below我的输入如下
Column A ![]() |
---|
ABC-5678-1/15/1 ![]() |
ABCD-7589-1/8/2 ![]() |
AB-78698-1/10/1 ![]() |
and required output is (only want to taken value between two /)并且所需的输出是(只想在两个 / 之间取值)
Column A ![]() |
---|
ABC-5678-15 ![]() |
ABCD-7589-8 ![]() |
AB-78698-10 ![]() |
You can use str.replace
with a regex, capturing groups, and references:您可以将
str.replace
与正则表达式、捕获组和引用一起使用:
df['Column A'].str.replace(r'^([^/]+-)[^-/]+/([^/]+)/.*', r'\1\2', regex=True)
Output:输出:
0 ABC-5678-15
1 ABCD-7589-8
2 AB-78698-10
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.