Search code examples
pythonpandasdata-analysis

The plot doesn't appear in Pandas


I was following a tutorial to learn data analysis to plot a graph and here is my code

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()

there is no bugs with the code as **there is no error massages ** only this line appear (with no graph)

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

Solution

  • You need to import matplotlib, and do a 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()