前提・実現したいこと
Googleトレンドで、複数のワードの検索結果を取得し、
結果をスプレッドシートへ格納するコーディングを試みています。
初心者につき、色々と調べながらコードを書いてみたのですが、
下記の通りエラーが表示されてしまいます。
発生している問題・エラーメッセージ
KeyError: "['isPartial'] not found in axis"
該当のソースコード
Python
1pytrends = TrendReq(hl='ja-JP', tz=360) 2 3List1 = ["検索ワード1","検索ワード2","検索ワード3"] 4List2 = [List1[0]] 5 6pytrends.build_payload(kw_list=List2, cat=0, timeframe='2021-09-20 2021-09-30', geo='JP', gprop='') 7df = pytrends.interest_over_time() 8df.drop("isPartial",axis=1,inplace=True) 9 10for i in range(1,len(List1)): 11 List2 = [List1[i]] 12 13 pytrends.build_payload(kw_list=List2, cat=0, timeframe='2021-09-20 2021-09-30', geo='JP', gprop='') 14 15 df2 = pytrends.interest_over_time() 16 df2.drop("isPartial",axis=1,inplace=True) 17 df[List1[i]] = df2 18 19 20from google.colab import auth 21from oauth2client.client import GoogleCredentials 22import gspread 23import gspread_dataframe as gs_df 24 25# 認証処理 26auth.authenticate_user() 27gc = gspread.authorize(GoogleCredentials.get_application_default()) 28 29worksheet = gc.open('スプレッドシート名').get_worksheet(0) 30 31gs_df.set_with_dataframe(worksheet, df) 32
試したこと
上記のエラーが出たのは
df.drop("isPartial",axis=1,inplace=True) と df2.drop("isPartial",axis=1,inplace=True)
この箇所なので、これを削除したところ、
今度は
ValueError: Cannot set a frame with no defined index and a value that cannot be converted to a Series
このようなエラーが表示されました。
恐れ入りますが、上記エラーの対処法をご存じの方いらっしゃいましたら、
ご教示いただけますと幸いです。
よろしくお願いいたします。
あなたの回答
tips
プレビュー