我得到以下数据框:
我合并了两个不同的列表。 Standstillreason的单元格中可能包含带有内容的列表,或者可能已经是“ NaN”。我的目标是将空列表(如上图所示)也转换为“ NaN”。 我是一个初学者,我知道.replace方法。但这似乎不起作用吗?
df.Standstillreason = df.Standstillreason.replace("", np.nan, inplace=True)
I tried to replace the ""
with []
, " "
, "[]"
and "[ ]"
. But all this code did was to replace the whole column with None
, even the non-empty cells.
What can I do, to transform only those cells with empty lists to NaN
?
Let us try
bool
详情