截断pandas列中的所有值

时间:2018-11-12 17:19:56

标签: python pandas

我试图用数字除后截断pandas中的列值。这是我尝试过的两种方法:

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

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

每次出现输入错误:

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

如何在避免这些错误的同时解决此问题?

1 个答案:

答案 0 :(得分:1)

代码需要将除法生成的Series转换为int

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