删除所有带有@登录的行

时间:2018-10-22 13:00:13

标签: python python-3.x pandas dataframe

我有一个如下所示的熊猫数据框:-

    Tweets
0   RT @cizzorz: THE CHILLER TRAP *TEMPLE RUN* OBS...
1   Disco Domination receives a change in order to...
2   It's time for the Week 3 #FallSkirmish Trials!...
3   Dance your way to victory in the new Disco Dom...
4   Patch v6.02 is available now with a return fro...
5   Downtime for patch v6.02 has begun. Find out a...
6   ⛏️... soon
7   Launch into patch v6.02 Wednesday, October 10!...
8   Righteous Fury.\n\nThe Wukong and Dark Vanguar...
9   RT @wbgames: WB Games is happy to bring @Fortn...

我想排除其中包含 @username 的所有推文,也许我可以说如果该推文中包含 @ 的标志,我希望将其排除在外df。 因此,我想忽略以下几行,然后将它们放入一个单独的df,并将其从原始行中删除。

 0  RT @cizzorz: THE CHILLER TRAP *TEMPLE RUN* OBS...
 9  RT @wbgames: WB Games is happy to bring @Fortn...

和其余的tweets将在同一df中。

P.S. - I just want to perform it for @ sign and for no other special character.

1 个答案:

答案 0 :(得分:1)

这只是过滤,我相信可以有条件地做到这一点。

尝试一下:

df[~df["Tweets"].str.contains("@")]

〜的作用类似于布尔运算符,然后检查子字符串@是否在每个Tweets单元内。