双循环到pd.DataFrame

时间:2019-03-25 11:19:49

标签: python python-3.x pandas

我有一个API调用,它给了我这个简单的对象输出:

pd.DataFrame(client.phrase_this(phrase='ciao', database='it', display_date='20140115')).set_index('Keyword')['Search Volume']

    Keyword
    ciao    368000
    Name: Search Volume, dtype: object

我想在2个变量上循环调用:

#instead of 'ciao'
phrase = query
query = ['ciao','google','microsoft']

#instead of '20140115'
display_date = date
date = ['20140115','20140215','20140315','20140415','20140515','20140615']

无效的循环:

df = pd.DataFrame()

for query in query:
    for date in date:
        df.append(pd.DataFrame(client.phrase_this(phrase=query, database='it', display_date=date)).set_index('Keyword')['Search Volume'])

我想要的输出(需要由“搜索量”值填充):

test = pd.DataFrame(index=date, columns=query)

非常感谢

0 个答案:

没有答案