这个问题在这里已有答案:
我有一个看起来像这样的df
list
[]
[8,8]
[0,9]
[]
此列的qtype为object
。如何从列中删除[]
并替换为np.nan?
我尝试过字符串替换,但括号不是
df.list = df.list.replace('"[]"','')
使用astype(bool)
df=df[df['list'].astype(bool)]
你也可以用这个:
In [432]: df[df.astype(str)['list'] != '[]']
Out[432]:
list
1 [8,8]
2 [0,9]