Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: cannot concatenate object of type '<class 'dict'>'; only Series and DataFrame objs are valid #1

Open
OrsoArmeno opened this issue Jun 26, 2020 · 3 comments

Comments

@OrsoArmeno
Copy link

OrsoArmeno commented Jun 26, 2020

Hello,

I am following religiously your tutorial, that is GREAT.

I ended up in having an issue though.

When I try to concatenate the results of my multiple searches
result = pd.concat(dicti, axis=1) result.columns = result.columns.droplevel(0) result = result.drop('isPartial', axis = 1)

I receive this error
TypeError: cannot concatenate object of type '<class 'dict'>'; only Series and DataFrame objs are valid

I have understood that Python doesn't allow me to concatenate the results of my searches, but I have no idea how to overcome this issue. Can you maybe help me?

(this is my first request on GitHub, so I apologize in advance if lacks the "etiquette" of this place)

@hichnicksemen
Copy link

hichnicksemen commented Aug 12, 2020

Hi Hulya, i have the same question. Can you explain why we can't concatenate dict here?

@OrsoArmeno
Copy link
Author

OrsoArmeno commented Aug 12, 2020

hi @hichnicksemen .
i have found a workaround since when I wrote my issue:

import pytrends
from pytrends.request import TrendReq
import pandas as pd
import time
import datetime
from datetime import datetime, date, time

pytrend = TrendReq()

searches = ['kw1', 'kw2', 'kw2', 'kw3']

groupkeywords = list(zip(*[iter(searches)]*1))
groupkeywords = [list(x) for x in groupkeywords]

dicti = {}
i = 1
for trending in groupkeywords:
    pytrend.build_payload(trending, geo = 'US', timeframe = 'today 3-m', cat = 1)
    dicti[i] = pytrend.interest_over_time()
    i+=1

result = pd.concat(dicti, axis=1)
result.columns = result.columns.droplevel(0)
result = result.drop('isPartial', axis = 1)
result.reset_index(level=0, inplace=True)
pd.melt(result, id_vars='date', value_vars=searches)
print(result)

I hope it works

@hichnicksemen
Copy link

@OrsoArmeno Thanks, i'll try!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants