Error TypeError: 'DataFrame' object is not callable

Hi,

Building an app with this API GitHub - GeneralMills/pytrends: Pseudo API for Google Trends

I’ve made it to work in Jupyter, but for some reason can’t replicate using Streamlit.

It’s breaking on this line of code :
else:

    kw_list = removeRestrictedCharactersAndWhiteSpaces(linesList)
    
    pytrend.build_payload(kw_list, timeframe=selected_timeframe, geo=country_code[0], cat=category_ids[0])
    historic_interest = pd.DataFrame(
        pytrend.get_historical_interest(kw_list,year_start=year_from, month_start=month_from, day_start=day_from, year_end=year_to, month_end=month_to, day_end=day_to)
    )

Error Traceback

File "/Users/lazarinastoy/.local/lib/python3.8/site-packages/streamlit/script_runner.py", line 350, in _run_script
    exec(code, module.__dict__)File "/Users/lazarinastoy/Desktop/pytrendstest/streamlit_app.py", line 149, in <module>
    pytrend.get_historical_interest(kw_list,year_start=year_from, month_start=month_from, day_start=day_from, year_end=year_to, month_end=month_to, day_end=day_to)File "/Users/lazarinastoy/.local/lib/python3.8/site-packages/pytrends/request.py", line 490, in get_historical_interest
    df = pd.DataFrame()

Any help with this will be appreciated. :pray:

Hey @lazarinastoy, it’s great to see you here! Welcome to the Streamlit community! :raised_hands:

I’ve built a handful of Streamlit apps with the PyTrends library, so hopefully, I’ll be able to help you :slight_smile:

If possible, would you be able to share your app and its code to debug directly from there?

Best,
Charly

Thanks, Charly! :sunny:

I actually found out the resolution to this query, so I’ve not graduated to another type of error (LOL), will update the resolution and close this topic down. Will keep you posted with my code, if any help is needed, I’m chipping away at it slowly but surely.

Thanks Again. :blush:

For those interested: The error was that the pytrends api returns a df object as a response to the get_hisotrical_interest() function (indicated by the last row in the error log).

This needs to be wrapped up in a st.dataframe() when called in the web app.

Like this: :white_check_mark:

st.dataframe(
pytrend.get_historical_interest(kw_list,year_start=year_from, month_start=month_from, day_start=day_from, year_end=year_to, month_end=month_to, day_end=day_to, sleep=0)
)

Not like this: :x:

historic_interest = pd.DataFrame(
pytrend.get_historical_interest(kw_list,year_start=year_from, month_start=month_from, day_start=day_from, year_end=year_to, month_end=month_to, day_end=day_to)
)

1 Like

This topic was automatically closed 365 days after the last reply. New replies are no longer allowed.