1

I have dataset. A name of column is wage. Column's element contain K values. I want to replace K values.

data['Wage']=data['Wage'].replace("K","")

But it doesn't work.

my code is here

0

2 Answers 2

2

You can use:

data['Wage']=data['Wage'].replace("K","",regex=True)

Or:

data['Wage']=data['Wage'].astype(str).str.replace("K","")
Sign up to request clarification or add additional context in comments.

1 Comment

@Raşitİri check this too: df['Wage'].str.strip('k')
0

You can also use:

df = pd.DataFrame({'Wage': ['$200k', '$500']})
df['Wage'] = df['Wage'].str.split('k', expand=True)[0]
print(df)

Output:

   Wage
0  $200
1  $500

OR

df['Wage'] = df['Wage'].str.replace(r'k', '')
print(df)

Output:

   Wage
0  $200
1  $500

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.