我们有时候在对组数进行操作时候,偶尔会出现这个问题.

比如:

#coding:utf-
import pandas as pd
import numpy as np if __name__ == '__main__':
np.random.seed()
df = pd.DataFrame( + np.random.randn().cumsum(), columns=['weight'])
df['pct_change'] = df.weight.pct_change()
df['w_log'] = np.log(np.asarray(df['weight']+ , dtype=object))
print df['w_log']

会出现这个问题:

   df['w_log'] = np.log(np.asarray(df['weight']+ , dtype=object))
AttributeError: 'float' object has no attribute 'log'

这个问题的原因是object没有log操作:上述操作等同于

np.log(np.array([x], dtype=object)) <-> np.array([x.log()], dtype=object)

那么我们该怎么样来修正呢?
#coding:utf-
import pandas as pd
import numpy as np if __name__ == '__main__':
np.random.seed()
df = pd.DataFrame( + np.random.randn().cumsum(), columns=['weight'])
df['pct_change'] = df.weight.pct_change()
df['w_log'] = np.log(np.asarray(df['weight']+ , dtype=float))
print df['w_log']

将object对象,改成base类型就可以了.

结果:

     4.642120
4.645969
4.655321
4.676410
4.693652
4.684666
4.693403
4.692016
4.691069
4.694830
4.696146
4.709337
4.716171

完.

AttributeError: 'int' object has no attribute 'log'的更多相关文章

  1. AttributeError: 'int' object has no attribute 'isdigit'(python下的isdigit函数)

    python下的isdigit函数:  isdigit() 方法检测字符串是否只由数字组成. 语法 isdigit()方法语法:  str.isdigit() 示例代码如下: 结果: 我想说的重点在于 ...

  2. 解决代理池的问题AttributeError: 'int' object has no attribute 'items'

    https://blog.csdn.net/mygodit/article/details/86689127

  3. AttributeError: 'int' object has no attribute 'upper'

    因为安装的openpyxl版本是2.3.4,而代码是: sheet.cell(rownumber, 1).value = data['id']参数不对,应该是: sheet.cell(None, ro ...

  4. [已解决]报错:报错AttributeError: 'int' object has no attribute 'upper'

    原因:openpyxl版本低,需升级 pip install --upgrade openpyxl

  5. AttributeError: 'module' object has no attribute 'TornadoAsyncNotifier'

    /*************************************************************************** * AttributeError: 'modu ...

  6. 解决:pipenv shell报错:AttributeError: 'module' object has no attribute 'run'

    利用pipenv shell切换到虚拟环境时,显示报错:AttributeError: 'module' object has no attribute 'run' 可以看到是d:\program\p ...

  7. 测试类执行报错:AttributeError: 'Testlei' object has no attribute 'test_cases' 和data,unpack用法解析

    a=[{"}] import unittest from ddt import ddt,data,unpack @ddt class Testlei(unittest.TestCase): ...

  8. AttributeError: 'list' object has no attribute 'extends' && list详解

    拼写错误 是extend  而不是extends 出错demo: In [27]: c = [2,3] In [28]: c.extends([5]) ------------------------ ...

  9. Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法

    最近在编写Python脚本过程中遇到一个问题比较奇怪:Python脚本完全正常没问题,但执行总报错"AttributeError: 'module' object has no attrib ...

随机推荐

  1. Android开发——diglog cancel与dismiss方法区别

    AlertDialog dismiss 和 cancel方法的区别   AlertDialog使用很方便,但是有一个问题就是:dismiss方法和cancel方法到底有什么不同? 今天有时间,看了看源 ...

  2. mysql 证明为什么用limit时,offset很大会影响性能

    本文同时发表在https://github.com/zhangyachen/zhangyachen.github.io/issues/117 首先说明一下MySQL的版本: mysql> sel ...

  3. ArcGIS API for JavaScript 4.2学习笔记[6] goTo()地图动画

    这是个很有意思的例子,不过例子给的比较复杂,需要查很多API,我会在文章最后给出关键的类和属性解释. 同样发现一个很有意思的事儿:博客园似乎有爬虫,我4号发布的blogs,5号就在百度和google搜 ...

  4. 一口一口吃掉Volley(四)

    欢迎访问我的个人博客转发请注明出处:http://www.wensibo.top/2017/02/17/一口一口吃掉Volley(四)/ 非常感谢你能够坚持看到第四篇,同时这也是这个Volley系列教 ...

  5. Linux(CentOS6.5)修改默认yum源为国内的阿里云、网易yum源

    官方的yum源在国内访问效果不佳. 需要改为国内比较好的阿里云或者网易的yum源 修改方式: echo 备份当前的yum源 mv /etc/yum.repos.d /etc/yum.repos.d.b ...

  6. Linux(CentOS6.5)下创建新用户和组,并制定用户和组ID

    相关命令: groupadd -g 888 comexgroup useradd comex -d /comexHome -g comexgroup -u 888 cp /etc/skel/.* /c ...

  7. vue链接传参与路由传参

    1.链接传参: 例如:链接是:http://localhost:3333/#/index?id=001 我们要获取参数:console.log(this.$route.query.id):即可 2.路 ...

  8. hiberation4 获取session

    T t; Configuration cfg = new Configuration(); cfg.configure(); ServiceRegistry serviceRegistry = new ...

  9. 搭建PHP本地服务器(XAMPP)

    1.下载XAMPP集成包 https://www.apachefriends.org/download.html2.启动前修改配置文件httpd.conf的端口号,例如:Listen 80803.启动 ...

  10. Eclipse项目分组管理

    对于eclipse相信对于一个java开发人员,一定不陌生.eclipse可以通过工作空间(Workspace)将不同的项目进行分开管理,相信这一点大家一定很熟悉,用过idea的小伙伴,一定发现了,i ...