涉及动态数据框对象的嵌套熊猫迭代

时间:2019-02-15 15:44:18

标签: pandas dataframe datareader

我的脚本收集了F500公司的“实时”在线列表,遍历每个股票行情清单,并在定义的时间段内获取股票行情表现。我无法弄清楚的是如何将每个符号多行代码数据计划/存储到2D列表中。不知何故,第二次迭代将不起作用。预先感谢:

import pandas as pd #dataframe extends from pd
import pandas_datareader.data as web #grabs stock data
import datetime as dt #to specify date range for grab

#VARS:
#url to f500 list
data_url = "https://query.data.world/s/vjghzuarkh6dap3dblkxanppyh5jtl" 
source = "yahoo" 
start = dt.datetime(2019, 2, 13) #datetime type
end = dt.datetime.now()    
results = []

#read into memory
df500 = pd.read_csv(data_url)

for index, row in df500.tail().iterrows(): 

    try:

        dfdr = web.DataReader(row['SYMBOL'], source, start, end) #returns a dataframe presumably

        for index2, row2 in dfdr().iterrows(): 
            # here i want to append to the results list: row['SYMBOL'], row2['Date'], row2['High']
            print ("test output ", row2[0]) #not even this works

    except Exception as e: 
        pass

# commit to sqlite3 from list or df

1 个答案:

答案 0 :(得分:0)

此处dfdr后的括号是错误的:

dfdr().iterrows()

应该是:

dfdr.iterrows()