15

I try to get data from google trends in a g sheet. First time it runned smoothly, second time not so much. I got an error called:

ValueError: No objects to concatenate

I searched this error on Stack Overflow before but couldn't find any solutions. I use the code displayed below:

!pip install Pytrends
!pip install pandas
!pip install pytrends --upgrade <---------Note: this solved a different error.
from pytrends.request import TrendReq
import pandas as pd
import time
startTime = time.time()
pytrend = TrendReq(hl='nl-NL', tz=360)
df = wb = gc.open_by_url('https://docs.google.com/spreadsheets/d/1QE1QilM-GDdQle6eVunepqG5RNWv39xO0By84C19Ehc/edit?usp=sharing')
sheet = wb.sheet1
df2 = sheet.col_values(5)
d_from = sheet.acell('B7').value
d_to = sheet.acell('B8').value
geo1 = sheet.acell('B10').value
dataset = []
for x in range(1,len(df2)):
     keywords = [df2[x]]
     pytrend.build_payload(
     kw_list=keywords,
     cat=0,
     timeframe= str(d_from + " " + d_to),
     geo= str(geo1))
     data = pytrend.interest_over_time()
     if not data.empty:
          data = data.drop(labels=['isPartial'],axis='columns')
          dataset.append(data)
result = pd.concat(dataset, axis=1)
result.to_csv('search_trends_DOWNLOAD_ME.csv')
!cp search_trends_DOWNLOAD_ME.csv "/content/drive/My Drive/Colab Notebooks/Output"
executionTime = (time.time() - startTime)
print('Execution time in sec.: ' + str(executionTime))

The error I got:

ValueError                                Traceback (most recent call last)
<ipython-input-5-b86c7b4df727> in <module>()
     25           data = data.drop(labels=['isPartial'],axis='columns')
     26           dataset.append(data)
---> 27 result = pd.concat(dataset, axis=1)
     28 result.to_csv('search_trends_DOWNLOAD_ME.csv')
     29 get_ipython().system('cp search_trends_DOWNLOAD_ME.csv "/content/drive/My Drive/Colab Notebooks/Output"')

1 frames
/usr/local/lib/python3.6/dist-packages/pandas/core/reshape/concat.py in __init__(self, objs, axis, join, keys, levels, names, ignore_index, verify_integrity, copy, sort)
    327 
    328         if len(objs) == 0:
--> 329             raise ValueError("No objects to concatenate")
    330 
    331         if keys is None:

ValueError: No objects to concatenate

The keywords I use are located in df = wb = gc.open_by_url. It is a g-sheet with the location, language and the keywords.

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Luca
  • 151
  • 1
  • 1
  • 3
  • 3
    Seems like your `dataset` is empty, try printing it to screen earlier, similarly `df` and `df2` – Maciek Sep 21 '20 at 08:35
  • @Maciek Should i place "dataset = []" for example before "df2"? Would that work? – Luca Sep 21 '20 at 12:59
  • It wouldn't change anything. Maybe try what I suggested. – Maciek Sep 21 '20 at 14:06
  • @Maciek Sorry, than I dont really understand what you are suggesting with "earlier". This is my first code ever so i have no idea what to change if something is suggested to do, without example. That's what I am struggling with, while reading all other questions about this problem. Thanks for your reactions so far : ) – Luca Sep 21 '20 at 15:51
  • 1
    I meant you could print these variables to screen, not move the current instruction. – Maciek Sep 22 '20 at 07:58

1 Answers1

2

this happened to me earlier, it was just miss typing path\url of the file. check the path again.

ali
  • 31
  • 4