Skip to content

Commit

Permalink
Merge pull request #548 from Terseus/remove-nested-to-record
Browse files Browse the repository at this point in the history
Replace nested_to_record with json_normalize
  • Loading branch information
emlazzarin authored Nov 12, 2022
2 parents 3f4a0c2 + 579e136 commit 63b5c68
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions pytrends/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import pandas as pd
import requests

from pandas.io.json._normalize import nested_to_record
from requests.adapters import HTTPAdapter
from requests.packages.urllib3.util.retry import Retry
from requests import status_codes
Expand Down Expand Up @@ -348,20 +347,16 @@ def related_topics(self):

# top topics
try:
top_list = req_json['default']['rankedList'][0][
'rankedKeyword']
df_top = pd.DataFrame(
[nested_to_record(d, sep='_') for d in top_list])
top_list = req_json['default']['rankedList'][0]['rankedKeyword']
df_top = pd.json_normalize(top_list, sep='_')
except KeyError:
# in case no top topics are found, the lines above will throw a KeyError
df_top = None

# rising topics
try:
rising_list = req_json['default']['rankedList'][1][
'rankedKeyword']
df_rising = pd.DataFrame(
[nested_to_record(d, sep='_') for d in rising_list])
rising_list = req_json['default']['rankedList'][1]['rankedKeyword']
df_rising = pd.json_normalize(rising_list, sep='_')
except KeyError:
# in case no rising topics are found, the lines above will throw a KeyError
df_rising = None
Expand Down

0 comments on commit 63b5c68

Please sign in to comment.