bananaboy
bananaboy

Reputation: 139

Replacin values of a pandas column

I have the following dataframe:

col1
01
1
02
2
03
3
00
0

How can I replace values in col1 to be like the expected output below:

Expected Output:

col1
1
1
2
2
3
3
0
0

Upvotes: 0

Views: 55

Answers (3)

Omri
Omri

Reputation: 493

df['col1'] = df['col1'].map(int)

Upvotes: 0

salman
salman

Reputation: 316

You can do it like this:

df['col1'] = df['col1'].astype('int')

Upvotes: 1

Khaled DELLAL
Khaled DELLAL

Reputation: 921

Can you try this?

df['col1']=[int(x) for x in df['col1']]

Upvotes: 1

Related Questions