python - LXML : Populating Pandas DataFrame -


i running following code , works populate dataframe 1 line of information. parsing more information , appending dataframe. not want run:

d.setdefault('stat_name', []) 

for each statistic want parse , add. there more efficient way this?

url = 'http://finance.yahoo.com/q/is?s=mmm+income+statement&annual' tree = html.parse(url) years = ['year1', 'year2', 'year3'] d = {} d.setdefault('total revenue', []) in range(2,5):     contentb = tree.xpath("//table[@class='yfnc_tabledata1']/tr[1]/td/table/tr[3]/td[{i}]".format(i=i))[0].text_content().strip()     d['total revenue'].append(int(contentb.replace(',', ''))) df = pd.dataframe(columns=years, index=d.keys()) eachitem in d.values():     pass df.loc['total revenue'] = eachitem print(df) 


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -