python-3.x 我得到了以下错误:“DataFrame”对象没有属性“year”

ryoqjall  于 2023-07-01  发布在  Python
关注(0)|答案(1)|浏览(177)

picture of csv file containing raw data我试图绘制一个散点图使用一个在线的csv文件我下载了为了得到线性回归。%matplotlib inline plt.scatter(df.year, df.income(US), color='red', marker='+')
错误消息如下:属性错误:“DataFrame”对象没有属性“year”

vuktfyat

vuktfyat1#

year是一个索引,所以你可以这样得到它:

plt.scatter(df.index, df["income(US)"], color='red', marker='+')

同样,如果你试图得到这样的收入值df.income(US),你会得到一个错误AttributeError: 'DataFrame' object has no attribute 'income'。仅当列名不包含特殊符号时才允许这样做。df["income(US)"]正确。

相关问题