【发布时间】:2016-11-16 21:54:41
【问题描述】:
所以我正在收集有关股票列表的数据并将所有这些信息放入数据框中。该名单有大约700只股票。
import pandas as pd
stock =['adma','aapl','fb'] # list has about 700 stocks which I extracted from a pickled dataframe that was storing the info.
#The site I'm visiting is below with the name of the stock added to the end of the end of the link
##http://finviz.com/quote.ashx?t=adma
##http://finviz.com/quote.ashx?t=aapl
我只是提取该网站的一部分,下面代码中的 [-2] 很明显
df2 = pd.DataFrame()
for i in stock:
df = pd.read_html('http://finviz.com/quote.ashx?t={}'.format(i), header =0)[-2].set_index('SEC Form 4')
df['Stock'] = i.upper() # creating a column which has the name of the stock, so I can differentiate between stocks
df2 = df2.append(df)
感觉每次迭代我都在做几秒钟,而我现在有大约 700 次要完成。它不是很慢,但我只是好奇是否有更有效的方法。谢谢。
【问题讨论】:
-
查看我的question,或许这对你有帮助。
标签: pandas web-scraping