我有一个数据框 df ,其值如下:
Common_words count
0 realdonaldtrump 2932
2 new 2347
3 2030
4 trump 2013
5 good 1553
6 1440
7 great 200
我只需要有特定文本的行。例如,需要删除第 3 行和第 6 行等具有空白值的行。
Tried:
df = df.dropna(how='any',axis=0)
但我仍然得到相同的结果。我觉得这些不是空值而是空格,所以我也在下面尝试过:
df.Common_words = df.Common_words.str.replace(' ', '')
但结果还是一样。第 3 行和第 6 行仍未删除。该怎么办?
你可以做:
df.Common_words = df.Common_words.replace(r"\s+", np.NaN, regex=True)
df.dropna()
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句