闲置和Pandas-Python

3
我正在试图启动一个IPython笔记本中找到的代码(我还添加了一些代码,比如:interactive(True)...),但当我在Idle中使用“run module”时,它会启动“data.plot”,然后加载但什么也不发生。data.plot似乎无法工作。谢谢,如果您有任何想法。注意:如果没有“interactive(True)”,会弹出一个带有“Runtime error”的框。
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib import interactive
interactive(True)

# read data into a DataFrame
data = pd.read_csv('http://www-bcf.usc.edu/~gareth/ISL/Advertising.csv', index_col=0)
print(data.head())

# print the shape of the DataFrame
print data.shape

# visualize the relationship between the features and the response using scatterplots
fig, axs = plt.subplots(1, 3, sharey=True)
data.plot(kind='scatter', x='TV', y='Sales', ax=axs[0], figsize=(16, 8))
data.plot(kind='scatter', x='Radio', y='Sales', ax=axs[1])
data.plot(kind='scatter', x='Newspaper', y='Sales', ax=axs[2])
1个回答

6
尝试使用 display(data.plot(PARAMS)) 来显示数据。要导入,请尝试使用 from IPython.core.display import display。这在一些 iPython Notebooks 中对我有效。

我遇到了一个错误 "NameError: name 'display' is not defined",我应该添加哪个库? - bouritosse

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接