AttributeError: 'int' object has no attribute 'log'
我们有时候在对组数进行操作时候,偶尔会出现这个问题.
比如:
#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'的更多相关文章
- AttributeError: 'int' object has no attribute 'isdigit'(python下的isdigit函数)
python下的isdigit函数: isdigit() 方法检测字符串是否只由数字组成. 语法 isdigit()方法语法: str.isdigit() 示例代码如下: 结果: 我想说的重点在于 ...
- 解决代理池的问题AttributeError: 'int' object has no attribute 'items'
https://blog.csdn.net/mygodit/article/details/86689127
- AttributeError: 'int' object has no attribute 'upper'
因为安装的openpyxl版本是2.3.4,而代码是: sheet.cell(rownumber, 1).value = data['id']参数不对,应该是: sheet.cell(None, ro ...
- [已解决]报错:报错AttributeError: 'int' object has no attribute 'upper'
原因:openpyxl版本低,需升级 pip install --upgrade openpyxl
- AttributeError: 'module' object has no attribute 'TornadoAsyncNotifier'
/*************************************************************************** * AttributeError: 'modu ...
- 解决:pipenv shell报错:AttributeError: 'module' object has no attribute 'run'
利用pipenv shell切换到虚拟环境时,显示报错:AttributeError: 'module' object has no attribute 'run' 可以看到是d:\program\p ...
- 测试类执行报错:AttributeError: 'Testlei' object has no attribute 'test_cases' 和data,unpack用法解析
a=[{"}] import unittest from ddt import ddt,data,unpack @ddt class Testlei(unittest.TestCase): ...
- AttributeError: 'list' object has no attribute 'extends' && list详解
拼写错误 是extend 而不是extends 出错demo: In [27]: c = [2,3] In [28]: c.extends([5]) ------------------------ ...
- Python脚本报错AttributeError: ‘module’ object has no attribute’xxx’解决方法
最近在编写Python脚本过程中遇到一个问题比较奇怪:Python脚本完全正常没问题,但执行总报错"AttributeError: 'module' object has no attrib ...
随机推荐
- JavaScrpit判断横竖屏
JavaScript function setLandscapeClass(){ if(window.orientation === 90 || window.orientation === -90 ...
- css经典布局—stick footer布局
html部分 <div id="wrap"> <div id="main" class="clearfix"> &l ...
- 自学Zabbix9.3 zabbix客户端自动注册
自学Zabbix9.3 zabbix客户端自动注册 1. 概述 网络自动发现配置,只要就是zabbix server去扫描一个网段,把在线的主机添加到Host列表中.但是Active agent是主动 ...
- 应用activeMQ消息中间件同步索引库
mq是一个消息服务器: 安装包内置了tomcat,直接登录访问,登录:http://ip:8161/admin/ (相当于dubbo的moniter监控中心) admin admin传统串行化, ...
- Android项目实战(三十五):多渠道打包
多渠道打包: 可以理解为:同时发布多个渠道的apk.分别上架不同的应用商店.这些apk带有各自渠道的标签,用于统计分析各个商店的下载次数等数据. 实现步骤 一.添加友盟渠道标签 添加位置:app目录下 ...
- Kotlin——最详细的数据类、密封类详解
在前面几个章节章节中,详细的讲解了Koltin中的接口类(Interface).枚举类(Enmu),还不甚了解的可以查看我的上一篇文章Kotlin--接口类.枚举类详解.当然,在Koltin中,除了接 ...
- Akka Serialization
Akka本身使用了Protocol Buffers来序列化内部消息(比如gossip message).Akka系统还可以配置自定义序列化机制. 配置conf akka { actor { ## 在a ...
- 简单工厂(Simple Factory),最合适的设计模式首秀.
简单工厂又称为静态工厂方法(static factory method)模式,简单工厂是由一个工厂来决定创建出哪一种个体的实现,在很多的讨论中,简单工厂做为工厂方法模式(Factory Method) ...
- ubuntu下加载mcypt
mcrypt 是php 里面重要的加密支持扩展库,linux环境下:该库在默认情况下不开启.window环境下:PHP>=5.3,默认开启mcrypt扩展 1.命令行下载(不嫌麻烦可以到网上找安 ...
- css各种布局
1.水平居中 前提:父容器.parent 和子容器.child 1)使用text-align和inline-block .parent{text-aling:center}; .child {disp ...