Charlotte
Charlotte

Reputation: 89

Python pandas: Operation on a column - Error: must be str not int

I'm just trying to add 1 to all values in the column 'day' in df:

df
  day
1  1
2  2
3  3
0  0

I need:

df
  day
0  1
1  2
2  3
3  4

I tried:

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

and

df['day']+=1

Both results in ERROR: TypeError: must be str, not int

Upvotes: 2

Views: 6424

Answers (1)

jezrael
jezrael

Reputation: 863611

It seems error is:

ERROR: TypeError: must be int, not str

And solution:

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

Upvotes: 3

Related Questions