简体   繁体   English

当我运行来自 google colab w3school 的以下 python 代码时,我得到了“AttributeError: 'OutStream' object has no attribute 'buffer'”

[英]I got the "AttributeError: 'OutStream' object has no attribute 'buffer'" when i run the below python code that are from w3school in the google colab

Here I mention the code that I saw in the w3school.这里提一下我在w3school看到的代码。

    # w3school code
import sys
import matplotlib
matplotlib.use('Agg')

import pandas as pd
import matplotlib.pyplot as plt

health_data = pd.read_csv("data.csv", header=0, sep=",")

health_data.plot(x ='Average_Pulse', y='Calorie_Burnage', kind='line'),
plt.ylim(ymin=0, ymax=400)
plt.xlim(xmin=0, xmax=150)

plt.show()

#Two  lines to make our compiler able to draw:
plt.savefig(sys.stdout.buffer)
sys.stdout.flush()

And I got the error (AttributeError: 'OutStream' object has no attribute 'buffer') if I performed the above operation on Kaggle dataset in google colab via using the below code.如果我通过使用以下代码对 google colab 中的Kaggle数据集执行上述操作,我会收到错误消息(AttributeError: 'OutStream' object has no attribute 'buffer')。

 #Three lines to make our compiler able to draw:
import sys
import matplotlib
matplotlib.use('Agg')

import pandas as pd
import matplotlib.pyplot as plt

health_data = pd.read_csv("/content/drive/MyDrive/India_GDP_Data.csv", header=0, sep=",")

health_data.plot(x ='Year', y='GDP_In_Billion_USD', kind='line'),
plt.ylim(ymin=0, ymax=400)
plt.xlim(xmin=0, xmax=150)

plt.show()

#Two  lines to make our compiler able to draw:
plt.savefig(sys.stdout.buffer)
sys.stdout.flush()

I had this same issue on W3schools as well!我在 W3schools 上也有同样的问题!

Use matplotlib inline in you notebook like this:像这样在你的笔记本中使用matplotlib inline

%matplotlib inline

import pandas as pd
import matplotlib.pyplot as plt

df = pd.read_csv('data.csv')

df.plot()

plt.show()

sys.stdout.flush()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我在 python 中运行下面的代码并收到错误 'AttributeError: 'QgridWidget' object has no attribute 'to_excel'' - I am running the code below in python and getting the error 'AttributeError: 'QgridWidget' object has no attribute 'to_excel'' ```AttributeError: 'module' object has no attribute 'set_random_seed'``` 当我从终端运行 ```python2 ./train.py``` 时 - ```AttributeError: 'module' object has no attribute 'set_random_seed'``` when i run ```python2 ./train.py``` from the terminal AttributeError: 'NoneType' object 在我运行代码时在 python 中没有属性 'split' - AttributeError: 'NoneType' object has no attribute 'split' in python when I rune my code AttributeError: 'tuple' object 没有以下代码的属性 - AttributeError: 'tuple' object has no attribute for the code below 在执行下面的代码时,我得到了“AttributeError:World实例没有属性'fire'”。 我该怎么办? - I got “AttributeError: World instance has no attribute 'fire' ” while executing below code. what should i do? 我得到了这个AttributeError:'module'对象没有属性'QuerySet' - i got this AttributeError: 'module' object has no attribute 'QuerySet' 我收到此错误 AttributeError: 'function' object has no attribute 'hlauncher' while试图从另一个文件中获取属性 - I got this error AttributeError: 'function' object has no attribute 'hlauncher' while trying to get a attribute from another file 与此下面的代码我得到错误AttributeError:'str'对象没有属性'items', - with This below Code i am getting error AttributeError: 'str' object has no attribute 'items' , 我运行时 Flask 出现属性错误(AttributeError: 'NoneType' object has no attribute 'run' ) - attribute error in Flask when I run (AttributeError: 'NoneType' object has no attribute 'run' ) Object 检测 Google Colab: AttributeError: module 'tensorflow' has no attribute 'contrib' - Object Detection Google Colab: AttributeError: module 'tensorflow' has no attribute 'contrib'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM