简体   繁体   English

使用 Pandas 从字符串列表中删除 substring

[英]Remove a substring from a list of string using Pandas

I'm trying to search some post related to remove substring key but unfortunately those solutions don't work in my case.我正在尝试搜索一些与删除 substring 密钥相关的帖子,但不幸的是,这些解决方案不适用于我的情况。

Could you help me?你可以帮帮我吗?

Input:输入:

['Female/Fri', 'Male/Fri', 'Female/Sat', 'Male/Sat', 'Female/Sun','Male/Sun', 'Female/Thur', 'Male/Thur', 'Female', 'Male']

Output Output

['Fri', 'Fri', 'Sat', 'Sat', 'Sun','Sun', 'Thur', 'Thur', 'Female', 'Male']

You don't even need pandas for that.你甚至不需要 pandas 。 A simple list comprehension should be enough一个简单的列表理解就足够了

In [3]: [s.split('/')[-1] for s in ['Female/Fri', 'Male/Fri', 'Female/Sat', 'Male/Sat', 'Female/Sun','Male/Sun', 'Female/Thur', 'Male/Thur', 'Female', 'Male']]
Out[3]: ['Fri', 'Fri', 'Sat', 'Sat', 'Sun', 'Sun', 'Thur', 'Thur', 'Female', 'Male']

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

相关问题 如何使用 Pandas 从给定字符串中删除 substring - How can I remove a substring from a given String using Pandas 如果从子字符串列表中删除列表中的字符串 - Remove string from list if from substring list 用列表中的子字符串替换 Pandas 列中的字符串 - Replace string in Pandas column by substring from list Python - 从列表中的字符串元素中删除子字符串? - Python - Remove substring from string element in a list? 如果 substring 在数据框列的列表中,则从字符串中删除 substring - Remove substring from string if substring in list in data frame column 在熊猫中,检查主字符串是否包含列表中的字符串,是否确实从主字符串中删除了子字符串并将其添加到新列中 - In pandas, check if a master string contains a string from a list, if it does remove the substring from the master string and add it to a new column 使用python从字符串中删除子字符串 - remove substring from string using python 从pandas DataFrame中的多个字符串列中删除子字符串 - Remove substring from multiple string columns in a pandas DataFrame 如果来自另一个对象的字符串包含子字符串,则从列表中删除项目 - Remove item from list if a string from another object contains substring 如何从字符串列表中删除重复的子字符串? - How do I remove repeating substring from a list of string?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM