标签: attributeerror

AttributeError:模块“matplotlib”没有属性“xlabel”

我的代码是:

import matplotlib as plt 
sns.distplot(CMSU['Spending'], kde = False)
plt.xlabel("Spending", size=15)
plt.ylabel("Probablity", size=15)
plt.title("Distribution for the variable - Spending", size=18);
Run Code Online (Sandbox Code Playgroud)

我收到错误:

AttributeError                            Traceback (most recent call last)
<ipython-input-32-1c6eb744a592> in <module>
      1 sns.distplot(CMSU['Spending'], kde = False)
----> 2 plt.xlabel("Spending", size=15)
      3 plt.ylabel("Probablity", size=15)
      4 plt.title("Distribution for the variable - Spending", size=18);

AttributeError: module 'matplotlib' has no attribute 'xlabel'
Run Code Online (Sandbox Code Playgroud)

可能会出现什么问题?

python matplotlib attributeerror

3
推荐指数
1
解决办法
2万
查看次数

AttributeError:“超级”对象没有属性“word_weighting”

我有一个超级班FTM

class FTM:
    def __init__(self,word_weighting = 'normal'):
        self.word_weighting = word_weighting
    
    def get_sparse_global_term_weights(self, word_weighting):
        pass
Run Code Online (Sandbox Code Playgroud)

以及继承自的子类FTM

class FLSA(FTM):
    def __init__(self, word_weighting='normal'):
        super().__init__(word_weighting = word_weighting)
        self.sparse_global_term_weighting = super().get_sparse_global_term_weights(word_weighting = super().word_weighting)
        
Run Code Online (Sandbox Code Playgroud)

运行此代码,我收到以下错误:

AttributeError: 'super' object has no attribute 'word_weighting'
Run Code Online (Sandbox Code Playgroud)

我已经初始化了该属性。为什么我会收到此错误?

inheritance class super attributeerror python-3.x

3
推荐指数
1
解决办法
2283
查看次数

Matplotlib - AttributeError:“version_info”对象没有属性“__version__”

我不知道如何修复这个错误。我尝试到处寻找。仅当我尝试与 matplotlib 交互时才会出现此错误。我的 pip 已完全升级,我正在使用 python 3.6.0 进行课程。谢谢你!

Python 3.6.0(v3.6.0:41df79263a11,2016 年 12 月 23 日,07:18:10)[MSC v.1900 32 位(英特尔)] 在 win32 上键入“帮助”、“版权”、“积分”或“许可证”了解更多信息。

导入matplotlib Traceback(最近一次调用最后一次):文件“”,第1行,在文件“C:\ Users \ syner \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ site-packages \ matplotlib_ init _.py中”,第 107 行,来自 . 导入cbook,rcsetup文件“C:\ Users \ syner \ AppData \ Local \ Programs \ Python \ Python36-32 \ lib \ site-packages \ matplotlib \ rcsetup.py”,第28行,来自matplotlib.fontconfig_pattern导入parse_fontconfig_pattern文件“ C:\Users\syner\AppData\Local\Programs\Python\Python36-32\lib\site-packages\matplotlib\fontconfig_pattern.py",第 15 行,来自 pyparsing 导入(文字、ZeroOrMore、可选、正则表达式、StringEnd、文件“C:\ Users \ syner \ AppData …

python matplotlib attributeerror

3
推荐指数
1
解决办法
1万
查看次数

pandas 附加 excel(xlsx) 文件给出 attribute.error

因任一错误而遇到麻烦;writer.book=book AttributeError: can't set attribute 'book'或者BadZipFile

对于没有给出 badzipfile 错误的代码,我首先放置了写入 excel 文件的代码行,dataOutput=pd.DataFrame(dictDataOutput,index=[0]) 但是,即使我无法摆脱,writer.book = book AttributeError: can't set attribute 'book'正如其中一个答案所示,我需要将 openpyxl 返回到以前的版本,或者使用 CSV 文件而不是 excel。我认为这不是解决方案。应该有我无法进入的解决方案

dataOutput=pd.DataFrame(dictDataOutput,index=[0])
dataOutput.to_excel('output.xlsx') 'output.xlsm'
book = load_workbook('output.xlsx') 'output.xlsm'
writer = pd.ExcelWriter('output.xlsx')OR'output.xlsm'#,engine='openpyxl',mode='a',if_sheet_exists='overlay')
writer.book = book
writer.sheets = {ws.title: ws for ws in book.worksheets}

for sheetname in writer.sheets:
    dataOutput.to_excel(writer,sheet_name=sheetname, startrow=writer.sheets[sheetname].max_row, index = False,header= False)

writer.save()
Run Code Online (Sandbox Code Playgroud)

我在此处输入链接描述中寻找答案,并在此处输入链接描述中属性错误的详细解决方案中寻找答案

---我尝试了另一种方法

with pd.ExcelWriter('output.xlsx', mode='a',if_sheet_exists='overlay') as writer:
    dataOutput.to_excel(writer, sheet_name='Sheet1')
    writer.save()
Run Code Online (Sandbox Code Playgroud)

但是这次又报错了

FutureWarning: save is not part …
Run Code Online (Sandbox Code Playgroud)

python attributeerror pandas openpyxl

3
推荐指数
1
解决办法
5421
查看次数

Python入门:属性错误

我是python的新手,今天就下载了它.我正在使用它来处理网络蜘蛛,所以为了测试它并确保一切正常,我下载了示例代码.不幸的是,它不起作用,并给我错误:

"AttributeError:'MyShell'对象没有'已加载'属性"

我不确定代码本身是否有错误,或者我在安装python时未能正确执行某些操作.安装python时是否需要做任何事情,比如添加环境变量等?那个错误通常意味着什么?

以下是我用于导入蜘蛛类的示例代码:

import chilkat
spider = chilkat.CkSpider()
spider.Initialize("www.chilkatsoft.com")
spider.AddUnspidered("http://www.chilkatsoft.com/")
for i in range(0,10):
    success = spider.CrawlNext()
    if (success == True):
        print spider.lastUrl()
    else:
        if (spider.get_NumUnspidered() == 0):
            print "No more URLs to spider"
        else:
            print spider.lastErrorText()

    #  Sleep 1 second before spidering the next URL.
    spider.SleepMs(1000)
Run Code Online (Sandbox Code Playgroud)

python web-crawler attributeerror chilkat

2
推荐指数
1
解决办法
6001
查看次数

字符串操作的基本Python问题:示例:string.lowercase

所以我试图运行它,但它出错了,我需要帮助理解什么是错的.我非常感谢任何帮助,我正在参加麻省理工学院开放式课程介绍编程:

words="GreatTimes"
words.lowercase
Run Code Online (Sandbox Code Playgroud)

我收到这个错误:

AttributeError: 'str' object has no attribute 'lowercase'
Run Code Online (Sandbox Code Playgroud)

问题是我正在尝试运行"如何像计算机科学家一样思考"中的示例代码,它仍然给我错误.

def isLower(ch):
    return string.find(string.lowercase, ch) != -1
Run Code Online (Sandbox Code Playgroud)

所以我无法弄清楚语法错误是什么.看一下Python doc页面,它说:

string.lowercase包含所有被视为小写字母的字符的字符串.在大多数系统中,这是字符串'abcdefghijklmnopqrstuvwxyz'.特定值取决于语言环境,并在调用locale.setlocale()时更新.

思考?

编辑:啊,对不起,我应该更清楚.所以我正在尝试编写一段代码,告诉我字符串中的字符是否小写.我的代码是我的实现.虽然示例代码是我用来尝试检查我的语法是否错误,这是问题的根源.但是,示例代码也会生成错误.简而言之,为什么这段代码不起作用?好像它应该吐出一串所有小写字母,如"GreatTimes"中的"reatimes"和/或你如何使用string.lowercase制作这个程序?

python string operations attributeerror

2
推荐指数
1
解决办法
1万
查看次数

使用python检查字典中是否存在键时的AttributeError

我正在使用Python 2.7.2+,当试图查看字典是否包含给定的字符串值(名为func)时,我得到以下异常:

Traceback (most recent call last):
  File "Translator.py", line 125, in <module>
    elif type == Parser.C_ARITHMETIC : parseFunc()
  File "Translator.py", line 95, in parseFunc
    if unary.has_key(func) : 
AttributeError: 'function' object has no attribute 'has_key'
Run Code Online (Sandbox Code Playgroud)

这是我定义词典的地方:

binary = {"add":'+', "sub":'-', "and":'&', "or":'|'}
relational = {"eq":"JEQ" , "lt":"JLT", "gt":"JGT"}
unary = {"neg":'-'}
Run Code Online (Sandbox Code Playgroud)

这是引发异常的函数:

def parseFunc():
    func = parser.arg1 
    print func  
    output.write("//pop to var1" + endLine)
    pop(var1)
    if unary.has_key(func) : // LINE 95
        unary()
        return
    output.write("//pop to var2" + endLine)
    pop(var2)
    result …
Run Code Online (Sandbox Code Playgroud)

python attributeerror

2
推荐指数
1
解决办法
1666
查看次数

python - AttributeError:'module'对象没有属性

我正在尝试这个简单的代码:

import requests
print requests.__file__
r = requests.get('https://github.com/timeline.json')
Run Code Online (Sandbox Code Playgroud)

当我逐行输入行时,它在命令行上完美地工作,但当我作为脚本或Sublime Text 2执行它时,它不是什么.这是堆栈跟踪:

C:\Python27\lib\site-packages\requests\__init__.pyc
Traceback (most recent call last):
  File "C:\Users\Bruce\Desktop\http.py", line 1, in <module>
    import requests
  File "C:\Python27\lib\site-packages\requests\__init__.py", line 53, in <module>
    from requests.packages.urllib3.contrib import pyopenssl
  File "C:\Python27\lib\site-packages\requests\packages\__init__.py", line 3, in <module>
    from . import urllib3
  File "C:\Python27\lib\site-packages\requests\packages\urllib3\__init__.py", line 16, in <module>
    from .connectionpool import (
  File "C:\Python27\lib\site-packages\requests\packages\urllib3\connectionpool.py", line 15, in <module>
    from http.client import HTTPConnection, HTTPException
  File "C:\Users\Bruce\Desktop\http.py", line 3, in <module>
    r = requests.get('https://github.com/timeline.json')
AttributeError: 'module' object has no …
Run Code Online (Sandbox Code Playgroud)

python attributeerror python-requests

2
推荐指数
1
解决办法
1万
查看次数

AttributeError:'module'对象没有属性'update_settings'scrapy 1.0.5

爬虫通过命令行正常工作,给出了以下错误:

2016-03-30 03:47:59 [scrapy] INFO: Scrapy 1.0.5 started (bot: scrapybot)
2016-03-30 03:47:59 [scrapy] INFO: Optional features available: ssl, http11
2016-03-30 03:47:59 [scrapy] INFO: Overridden settings: {'USER_AGENT': 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1)'}

Traceback (most recent call last):
  File "/home/ahmeds/scrapProject/crawler/startcrawls.py", line 11, in <module>
    process.crawl(onioncrawl)
  File "/usr/local/lib/python2.7/dist-packages/scrapy/crawler.py", line 150, in crawl
    crawler = self._create_crawler(crawler_or_spidercls)
  File "/usr/local/lib/python2.7/dist-packages/scrapy/crawler.py", line 166, in _create_crawler
    return Crawler(spidercls, self.settings)
  File "/usr/local/lib/python2.7/dist-packages/scrapy/crawler.py", line 32, in __init__
    self.spidercls.update_settings(self.settings)
AttributeError: 'module' object has no attribute 'update_settings'
Run Code Online (Sandbox Code Playgroud)

这是我根据最新文档按脚本运行我的爬虫的代码.我的scrapy版本是1.0.5. …

attributeerror scrapy python-2.7 scrapy-spider

2
推荐指数
1
解决办法
2066
查看次数

Python:json_normalize一个熊猫系列给出TypeError

我在熊猫系列中有成千上万行这样的json片段 df["json"]

[{
    'IDs': [{
        'lotId': '1',
        'Id': '123456'
    }],
    'date': '2009-04-17',
    'bidsCount': 2,
}, {
    'IDs': [{
        'lotId': '2',
        'Id': '123456'
    }],
    'date': '2009-04-17',
    'bidsCount': 4,
}, {
    'IDs': [{
         'lotId': '3',
         'Id': '123456'
    }],
    'date': '2009-04-17',
    'bidsCount': 8,
}]
Run Code Online (Sandbox Code Playgroud)

原始文件样本:

{"type": "OPEN","title": "rainbow","json": [{"IDs": [{"lotId": "1","Id": "123456"}],"date": "2009-04-17","bidsCount": 2,}, {"IDs": [{"lotId": "2","Id": "123456"}],"date": "2009-04-17","bidsCount": 4,}, {"IDs": [{"lotId": "3","Id": "123456"}],"date": "2009-04-17","bidsCount": 8,}]}
{"type": "CLOSED","title": "clouds","json": [{"IDs": [{"lotId": "1","Id": "23345"}],"date": "2009-05-17","bidsCount": 2,}, {"IDs": [{"lotId": "2","Id": "23345"}],"date": "2009-05-17","bidsCount": 4,}, {"IDs": [{"lotId": …
Run Code Online (Sandbox Code Playgroud)

python json normalize attributeerror pandas

2
推荐指数
1
解决办法
3299
查看次数