简体   繁体   中英

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.

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"

Expected result would be

 "transaction Client Name"

You can use replace function like this.

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

Here the regex in action

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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