Skip to content Skip to sidebar Skip to footer

Pandas Adding Scalar Value To Numeric Column?

Given a dataframe like this ImageId | Width | Height | lb0 | x0 | y0 | lb1 | x1 | y1 | lb2 | x2 | y2 0 abc | 200 | 500 | ijk | 115| 8 | zyx | 15 | 16 | www | 23 | 42

Solution 1:

You probably don't have an int dtype. Doing

df['x0'] = df['x0'].astype(int) + 1

should work

Solution 2:

If you are sure that the dtype of your column is int and your code doesn't work, you can do something like this.

df['x0'] = df['x0'].apply(lambda x : x+1)

OR

df.loc[:,'x0'] += 1

Post a Comment for "Pandas Adding Scalar Value To Numeric Column?"