0

I am working with a pandas dataframe. I would like to change the name in a column if it DOES NOT equal "false" to the word "NAMED".

df
   hash
0  false
1  false
2  asldkjfl645sd54
3  false
4  65s4d65a3s21d12
5  2s1d53a54d5f1a3

Desired output:

df
   hash
0  false
1  false
2  NAMED
3  false
4  NAMED
5  NAMED
1
  • 2
    df['hash'].where(df['hash'].eq('false'), 'NAMED') Commented Sep 18, 2019 at 18:23

1 Answer 1

3

You can try with this:

import pandas as pd

a = {'hash':['false','false','asldkjfl645sd54','34ds','65s4d65a3s21d12','2s1d53a54d5f1a3']}
df = pd.DataFrame(a)
df['hash'] = df['hash'].where(df['hash'] == 'false', 'NAMED')
print(df)

Output:

    hash
0  false
1  false
2  NAMED
3  NAMED
4  false
5  NAMED
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.