1

I wanted to change my variables on spesific column with dictionary values but it does not change. I tried several ways and but it does not work. My dataset has 47k rows and my dictionary has 30 different words so I will show some.

My dataset:

My dataset

Dictionary:

rolechange = {"\\Adv":"Adversary",
          "\\Sci":"Scientist",
          "\\Inn":"Innocent",
          "\\Und":"Undetermined"}

I'm trying

movies_df["Role Type"].replace(rolechange, inplace=True)

It does not gives error but result is same. I couldn't find similar question on here, sorry for if its duplicate.

2
  • Is possible get list from problematic column values? Like print (movies_df["Role Type"].head(10).tolist()) Commented Mar 14, 2022 at 12:29
  • It prints: ['\\\\Sci', '\\\\Inn', '\\\\Und', '\\\\Und', '\\\\Und', '\\\\Und', '\\\\Und', '\\\\Und', '\\\\Und', '\\\\Und'] Commented Mar 14, 2022 at 12:32

1 Answer 1

1

You just have to create raw strings (prefix 'r')

rolechange = {r"\\Adv":"Adversary",
              r"\\Sci":"Scientist",
              r"\\Inn":"Innocent",
              r"\\Und":"Undetermined"}

>>> df['Role Type'].replace(rolechange)

0       Scientist
1        Innocent
2    Undetermined
Name: Role Type, dtype: object
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.