File tree Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Expand file tree Collapse file tree 1 file changed +13
-4
lines changed Original file line number Diff line number Diff line change 33import json
44import sys
55
6+ from pandas .io .json .normalize import nested_to_record
67import pandas as pd
78import requests
89
@@ -270,13 +271,21 @@ def related_topics(self):
270271
271272 # top topics
272273 try :
273- df = pd . DataFrame ( req_json ['default' ]['rankedList' ][0 ]['rankedKeyword' ])
274- df = pd .DataFrame (df [ 'topic' ]. tolist ()). join ( df [[ 'value' ] ])
274+ top_list = req_json ['default' ]['rankedList' ][0 ]['rankedKeyword' ]
275+ df_top = pd .DataFrame ([ nested_to_record ( d , sep = '_' ) for d in top_list ])
275276 except KeyError :
276277 # in case no top topics are found, the lines above will throw a KeyError
277- df = None
278+ df_top = None
278279
279- result_dict [kw ] = df
280+ #rising topics
281+ try :
282+ rising_list = req_json ['default' ]['rankedList' ][1 ]['rankedKeyword' ]
283+ df_rising = pd .DataFrame ([nested_to_record (d , sep = '_' ) for d in rising_list ])
284+ except KeyError :
285+ # in case no rising topics are found, the lines above will throw a KeyError
286+ df_rising = None
287+
288+ result_dict [kw ] = {'rising' : df_rising , 'top' : df_top }
280289 return result_dict
281290
282291 def related_queries (self ):
You can’t perform that action at this time.
0 commit comments