How to search in a pandas dataframe column with the space in the column name

1700 views python
5

If I need to search if a value exists in a pandas data frame column , which has got a name without any spaces, then I simply do something like this

if value in df.Timestamp.values

This will work if the column name is Timestamp. However, I have got plenty of data with column names as 'Date Time'. How do I use the if in statement in that case? If there is no easy way to check for this using the if in statement, can I search for the existence of the value in some other way? Note that I just need to search for the existence of the value. Also, this is not an index column.

Thank you for any inputs

answered question

Use df[column_name].values

2 Answers

3

It's better practice to use the square bracket notation:

df["Date Time"].values

Which does exactly the same thing

posted this
3

You can use:

if value in df["Date Time"].values

posted this

Have an answer?

JD

Please login first before posting an answer.