Global Data Science Forum

 View Only
Expand all | Collapse all

AttributeError: 'dict' object has no attribute 'Date'

  • 1.  AttributeError: 'dict' object has no attribute 'Date'

    Posted Mon November 29, 2021 11:15 PM

    Hello Seniors,

    Is there any mistake in the following code?

    def make_graph(stock_data, revenue_data, stock):
        fig = make_subplots(rows=2, cols=1, shared_xaxes=True, subplot_titles=("Historical Share Price", "Historical Revenue"), vertical_spacing = .3)
        stock_data = stock_data[stock_data.Date <= '2021-06-30']
        revenue_data = revenue_data[revenue_data.Date <= '2021-06-30']
        fig.add_trace(go.Scatter(x=pd.to_datetime(stock_data.Date, infer_datetime_format=True), y=stock_data.Close.astype("float"), name="Share Price"), row=1, col=1)
        fig.add_trace(go.Scatter(x=pd.to_datetime(revenue_data.Date, infer_datetime_format=True), y=revenue_data.Revenue.astype("float"), name="Revenue"),      row=2, col=1)
        fig.update_xaxes(title_text="Date", row=1, col=1)
        fig.update_xaxes(title_text="Date", row=2, col=1)
        fig.update_yaxes(title_text="Price ($US)", row=1, col=1)
        fig.update_yaxes(title_text="Revenue ($US Millions)", row=2, col=1)
        fig.update_layout(showlegend=False,
        height=900,
        title=stock,
        xaxis_rangeslider_visible=True)
        fig.show()

    Thank you in advance.




    ------------------------------
    Zaw Oo
    ------------------------------


  • 2.  RE: AttributeError: 'dict' object has no attribute 'Date'

    Posted Tue November 30, 2021 06:17 AM
    Edited by Rajkumar Rajasekaran Tue November 30, 2021 06:23 AM
    Hi Zaw Oo,

    If Your Input variables =>  "stock_data" and "revenue_data"  are of type Dict , then the way  you filter is not correct.
    What  I understand that should be  a data frame  "stock_data" and "revenue_data".
    If yes , Can you list the column names of those Dataframes.

    Thanks,
    Raj


    ------------------------------
    Rajkumar Rajasekaran
    ------------------------------