Slavatron
Slavatron

Reputation: 2358

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".

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.

Upvotes: 1

Views: 928

Answers (1)

EdChum
EdChum

Reputation: 394031

Just do df['Column Name'] = NaN, simples

Upvotes: 2

Related Questions