简体   繁体   English

Pandas:删除 dataframe 列中特定字符之前的所有字符

[英]Pandas: Remove all characters before a specific character in a dataframe column

how can I remove all characters before a specific character in a Dataframe column?如何删除 Dataframe 列中特定字符之前的所有字符? In this example remove everything BEFORE the first comma (,) and of course the companies names will always be of varying length and rarely the same but always before the first comma.在此示例中,删除第一个逗号 (,) 之前的所有内容,当然,公司名称的长度总是不同的,而且很少相同,但总是在第一个逗号之前。

My Dataframe:我的 Dataframe:

    address
0   My Company Ltd, address, city, state, postcode, country
1   Business Plc, address, city, state, postcode, country
2   Work Harder Inc, address, city, state, postcode, country
3   Company Business People, address, city, state, postcode, country

Desired outcome:期望的结果:

    address
0   address, city, state, postcode, country
1   address, city, state, postcode, country
2   address, city, state, postcode, country
3   address, city, state, postcode, country

Using str.replace :使用str.replace

df["address"] = df["address"].str.replace(r'^[^,]*,\s*', '')

Here is a regex demo showing that the logic is working.这是一个正则表达式演示,显示逻辑正在运行。

暂无
暂无

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

相关问题 Pandas:删除特定字符重复4次的dataframe列中特定字符(最后一个特定字符)之前的所有字符 - Pandas: Remove all characters before a specific character (last specific character) in a dataframe column that specific character is repeated 4 times Pandas 数据框列删除第一个特定字符之前的字符串 - Pandas dataframe column remove string before the first specific character 如何删除 python 中 pandas df 列中某个字符之前的所有字符 - How to remove all characters before a certain character in pandas df column in python 将正则表达式应用于 pandas DataFrame 的每一行以删除特定单词之前的所有字符 - Applying regex to each row of a pandas DataFrame to remove all characters before a specific word 如何删除 Python 中特定字符之前的所有字符? - How to remove all characters before a specific character in Python? 删除 dataframe 列中的特定字符(“-”)及其后的字符 - Remove a particular character ("-") and characters after it in a column of dataframe 删除熊猫数据框中特定字符后的值 - Remove value after specific character in pandas dataframe 删除 pandas dataframe 中的所有特殊字符 - Remove all special characters in pandas dataframe 如何从 pandas dataframe 中特定列的所有值中删除所有非数字字符? - How can I remove all non-numeric characters from all the values in a particular column in pandas dataframe? 根据条件删除熊猫列中的特定字符 - Remove specific character in pandas column based on condition
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM