[英]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.