我希望从df中删除字符串中仅包含数字的所有行
这是数据帧的一部分
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]')]
在这里感谢任何帮助
答案 0 :(得分:1)
如果我们只担心ASCII数字0-9:
df = df[~df['question_stemmed'].str.isdigit()]
如果我们需要担心其他语言的unicode或数字:
df = df[~df['question_stemmed'].str.isnumeric()]
Pandas方法在内部调用相应的python方法。有关这些功能的工作原理,请参见What's the difference between str.isdigit, isnumeric and isdecimal in python?。