0

I am attempting to truncate column values in pandas after dividing by a number. Here are the two methods I have tried:

df['new'] = int('%.0f'%(df['old']/12))

df['new'] = int(df['old']/12)

Each time I get type errors:

cannot convert the series to <class 'float'>
cannot convert the series to <class 'int'>

How can I solve this problem while avoiding these errors?

a.powell
  • 1,572
  • 4
  • 28
  • 39

1 Answers1

1

The code needs to convert the Series generated by the division into int.

df['new'] = (df['old'] / 12).astype(int)
jeevs
  • 131
  • 5