【发布时间】:2020-06-29 17:33:07
【问题描述】:
我有一个数据框 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 行仍未删除。怎么办?
【问题讨论】:
-
''也不是 null/nan ,替换为np.nan -
声明:
df.Common_words = df.Common_words.str.replace(' ', np.nan)给出以下错误TypeError: repl must be a string or callable -
使用
df.Common_words.replace而不是str.replace