简体   繁体   English

Pandas DataFrame:删除非数字字符后的所有内容

[英]Pandas DataFrame: Remove everything after a non-digit character

I have a question that is similar to this one: Pandas DataFrame: remove unwanted parts from strings in a column 我有一个与此问题类似的问题: Pandas DataFrame:从列中的字符串中删除不需要的部分

The difference is that I want to remove all characters after a non digit character appear, for example: 区别在于,我想在出现非数字字符后删除所有字符,例如:

    time    result
1   09:00   52m2 +6
2   10:00   62m2+balkon
3   11:00   57.+2 balkona
4   12:00   30 m2
5   13:00   46(43)

I need to trim this data to: 我需要将此数据修剪为:

    time    result
1   09:00   52
2   10:00   62
3   11:00   57
4   12:00   30
5   13:00   46

I tried solutions from this , this and many more similar questions, but I couldn't find this specific use case. 我从this这个问题以及更多类似的问题中尝试了解决方案,但是我找不到这个特定的用例。

You can use extract : 您可以使用extract

df.result = df.result.str.extract('(\d+)', expand=False)
print (df)
    time result
1  09:00     52
2  10:00     62
3  11:00     57
4  12:00     30
5  13:00     46

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

相关问题 在熊猫数据框中的某些字符之前提取非数字字符 - Extract non-digit characters before certain character in pandas dataframe 删除Python中第一个非数字之后(包括第一个非数字)的所有非正则表达式的最佳方法 - Best non-regex way to remove all characters after and including the first non-digit in Python Pyparsing:带有至少一个非数字字符的单词 - Pyparsing: word with at least one non-digit character 在Python中使用.find查找第一个非数字字符 - Finding first non-digit character with .find in Python 删除 pandas dataframe 中第一个空格之后的所有内容 - Remove everything after the first whitespace in pandas dataframe 非数字字符的fail2ban模式与数字输入匹配 - fail2ban pattern for non-digit character matches input with digit python中的正则表达式:匹配两个单词之间的任何非数字字符 - regex in python: match any non-digit character between two words 删除熊猫数据框中特定字符后的值 - Remove value after specific character in pandas dataframe 如何在Dataframe中最后一次出现字符后删除所有内容? - How to remove everything after the last occurence of a character in a Dataframe? 删除第二个插入符正则表达式后的所有内容并应用于 pandas dataframe 列 - Remove everything after second caret regex and apply to pandas dataframe column
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM