首页 > 解决方案 > 情节没有出现在 Pandas 中

问题描述

我正在按照教程学习数据分析以绘制图表,这是我的代码

import pandas as pd
df=pd.read_csv("avocado.csv")
df["Date"]=pd.to_datetime(df["Date"])
albany_df=df[df["region"]=="Albany"]
albany_df.set_index("Date",inplace=True)
albany_df["AveragePrice"].plot()

代码没有错误,因为**没有错误消息**只有这一行出现(没有图表)

<matplotlib.axes._subplots.AxesSubplot at 0x2556f2158d0>

标签: pythonpandasdata-analysis

解决方案


您需要导入 matplotlib,并执行 show() :

import matplotlib.pyplot as plt
import pandas as pd

df=pd.read_csv("avocado.csv")
df["Date"]=pd.to_datetime(df["Date"])
albany_df=df[df["region"]=="Albany"]
albany_df.set_index("Date",inplace=True)
albany_df["AveragePrice"].plot()
plt.show()

推荐阅读