我有一个数据集,其中一列的值如下:001、002、XXX、R02、T01、003、004。 我需要从数据集中删除所有行,其中该列的值至少有 1 个格式为(R02、T01、XXX)的字母,并仅保留数字格式。 换句话说,我需要保留该列具有以下值的所有数据:001、002、003、004。
我尝试过使用以下函数,但没有成功。
searchfor = ['r', 't']
Filtered_Table = Filtered_Table[~Filtered_Table.ToBeDeleted2.str.contains('|'.join(searchfor))]
最佳答案
你也许可以用 pandas 做你想做的事情。
使用 df.drop()
https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFrame.drop.html
https://chrisalbon.com/python/data_wrangling/pandas_dropping_column_and_rows/
这两个链接有助于了解该函数的工作原理。
您还可以尝试使用正则表达式 re.search 方法。
关于Python - 需要删除数据框中的所有数据,其中一个特定列的值至少包含 1 个字母,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59737306/