简体   繁体   English

Pandas 删除指定字符序列后的部分字符串

[英]Pandas remove parts of string after specified character sequence

I would like to remove a part of a string from a value inside a dataframe, using pandas.我想使用 pandas 从 dataframe 中的值中删除字符串的一部分。

Value:价值:

"transaction  DATUM 07.03.2019, 07.48 UHR1.TAN 246915 DATUM 14.10.2019, 09.03 UHR1.TAN 620955 Client Name"

What I want is to remove "DATUM 07.03.2019, 07.48 UHR1.TAN 246915 DATUM 14.10.2019, 09.03 UHR1.TAN 620955"我想要的是删除“DATUM 07.03.2019, 07.48 UHR1.TAN 246915 DATUM 14.10.2019, 09.03 UHR1.TAN 620955”

Expected result would be预期的结果是

 "transaction Client Name"

You can use replace function like this.您可以像这样使用替换 function。

df["transaction"] = df["transaction"].str.replace(r"(?<=transaction\s).*(?=\sClient)", "")

Here the regex in action这里是正则表达式

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

相关问题 Pandas在数据帧内删除指定字符后的部分字符串 - Pandas delete parts of string after specified character inside a dataframe Pandas删除字符后的列中的所有字符串 - Pandas remove all of a string in a column after a character 用 pandas 替换/删除字符串的一部分 - Replace/remove parts of a string with pandas 在指定字符后删除字符串状索引的字符 - Remove characters of string-like index after specified character 如何删除 Pandas 中某个字符后的所有字符串或数字? - How to remove all string or numbers after certain Character in Pandas? pandas/regex: 去掉连字符或括号字符后的字符串(包括) carry string in the comma after the comma in pandas dataframe - pandas/regex: Remove the string after the hyphen or parenthesis character (including) carry string after the comma in pandas dataframe 从字符串中删除多个字符序列 - Remove multiples of character sequence from string 在熊猫中的特定字符后删除句子的一部分 - Remove part of a sentence after specific character in Pandas 删除熊猫数据框中特定字符后的值 - Remove value after specific character in pandas dataframe 如何为 Pandas 系列(或列表)的每个元素删除某个字符后的部分字符串? - How to remove portion of string after certain character for each element of a Pandas series (or list)?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM