![](/img/trans.png)
[英]How to remove rows in a Pandas Dataframe with a specific column containing numbers only?
[英]Remove rows from pandas dataframe if string has 'only numbers'
我希望从 df 中删除字符串中只有数字的所有行
这是 dataframe 的摘录
qid question_stemmed target question_length total_words
149952 1d53c9c017999b4f77e2 8430397824532987451912384179815150754023741609... 0 241 3
有没有办法我可以做到这一点?
我尝试了以下方法,但它将删除字符串中包含数字的所有行(以及任何其他数据类型)。 但是,我正在寻找是否可以删除所有“仅限数字”行。
df['question_stemmed'] = df[df['question_stemmed'].str.contains(r'[^a-z]')]
在这里感谢任何帮助
如果我们只关心 ASCII 数字 0-9:
df = df[~df['question_stemmed'].str.isdigit()]
如果我们需要担心 unicode 或其他语言的数字:
df = df[~df['question_stemmed'].str.isnumeric()]
Pandas 方法在内部调用相应的 python 方法。 请参阅python 中的 str.isdigit、isnumeric 和 isdecimal 有什么区别? 有关这些功能如何工作的说明。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.