arrays - Using Python 3, Is there a quicker way to pick out particular cell values in an excel spreadsheet besides sorting through lists generated by xlrd? -


def data_search(security, statistic):     """takes in specific asset , desired statistic (e.g. 'gross er', 'asset class', etc),     returns answer cme or equity ranking template spreadsheet"""     securities = xlrd.open_workbook('desktop\\cme.xlsx').sheet_by_index(1)     securities_array = securities.col_values(1, start_rowx = 1, end_rowx = securities.nrows)     desired_security_row = securities_array.index(security) + 1     statistics_array = securities.row_values(0, start_colx = 0, end_colx = securities.ncols)     statistic_index = statistics_array.index(statistic)     return securities.row(desired_security_row)[statistic_index].value 

i'm using python's xlrd read excel spreadsheet gather information , form list of financial data different assets. "cme" spreadsheet referenced in code above spreadsheet has 500 different financial assets ticker/symbol (e.g. 'aapl') running down column b on spreadsheet. x-axis has bunch of headers desired statistic such "gross expected return" , "yield". want able feed particular ticker , desired statistic function , return statistic ticker. code uses xlrd @ column b , generate list out of 500 securities (eg. ['aapl', 'schb', 'db', ...])then finds index of security how identifies right row. generates list of statistic types on spreadsheet (e.g. ['gross expected return', 'yield', 'beta', ...]) , finds index of desired statistic. @ correct row , return value of whatever's in cell of correct index.

when run for-loop calling function x amount of times on list of tickers, appears highly inefficient. curious see if had ideas on faster way either involving or not involving xlrd.


Comments

Popular posts from this blog

angular - Ionic slides - dynamically add slides before and after -

minify - Minimizing css files -

Add a dynamic header in angular 2 http provider -