[英]Pandas - How can I make every value within a column NaN?
I want to clear all the data from a column within my dataframe but keep the dataframe exactly the same. 我想清除数据框内某列的所有数据,但保持数据框完全相同。
The Excel equivalent of this would be to select all the data in a column beneath the header and right-click "Clear Contents". Excel的等效方法是选择标题下一列中的所有数据,然后右键单击“清除内容”。
I tried this: 我尝试了这个:
test = df.replace(to_replace=df('Column Name'), value=NaN)
but got an error stating: 但出现错误说明:
TypeError: 'DataFrame' object is not callable
I don't know what that means or how to think about changing my code. 我不知道这意味着什么,或者不知道如何更改代码。
只需df['Column Name'] = NaN
, 简单
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.