(pandas) 如何过滤掉包含问号的推文?

(pandas) how to filter out tweets that contain a question mark?

数据在 CSV 文件中。试图过滤掉所有带有问号的推文,但我试过的代码中 none 有效。该代码仅在“?”时有效是单元格中唯一的东西,而不是当它是一个完整的句子时,即 'where is my dog?')

我试过的代码: new_df = df[(df.astype(str) != '?').all(axis=1)] new_df = df['content'].str.contains("\?") new_df = df[df['content'].str.contains("\?")]

为什么以上代码都不起作用?即使我的 CSV 中的文本被评估为一个对象,它现在也应该被评估为一个字符串?

给你:

df = df[~df['content'].str.contains('\?')]