如何使用日志值将新列添加到Pandas数据框

时间:2019-04-26 10:37:58

标签: python

我有followig pandas df,

   Price  Generic
0     3.5     3
1       2     4
3     3.4    23

我想用日志值创建新列:

import numpy as np
df["log Price"]=np.log(df["Price"])

但不起作用,错误是:

AttributeError: 'Series' object has no attribute 'float'

我尝试将类型转换为float:

df['Price'] = df['Price'].float()

**AttributeError**: 'Series' object has no attribute 'float'

谢谢!

1 个答案:

答案 0 :(得分:0)

转换应像这样完成:

df['Price'] = df['Price'].astype('float64')