I am in need of some major help as I am relatively new to Python. I need to perform a task which will read data from Excel, and then allow me to sort it out in descending order. I have initially started working to put into a dictionary as the Excel File has a header row, and then thousands of rows after which contain data. I know dictionaries are not "sortable" per se, but I thought a dictionary would be the best approach, given what I need. However, I'm wondering if maybe a dataframe would work, but need any and all guidance as I'm struggling to figure this out.
I need to get the 3 largest commodities by share for each county, including the commodity name. For instance, for the first row, Lynd County, I want the following returned - Corn - 19.52, Cattle - 13.68, Strawberry - 12.31. It could also be like this Corn: 19.52, Cattle: 13.68, Strawberry: 12.31. However, I need to sort the data by the values for each commodity.
I found the following code online and used it to read Excel Data into a list structure that consisted of dictionaries, but I'm not really sure if this is the best approach.
import xlrd
from xlrd import open_workbook
book = open_workbook('DictionaryProject.xlsx')
sheet = book.sheet_by_name('Sheet1')
keys = [sheet.cell(0, col_index).value for col_index in range(sheet.ncols)]
dict_list =[]
for row_index in range(1, sheet.nrows):
d= {keys[col_index]: sheet.cell(row_index, col_index).value
for col_index in range(sheet.ncols)}
dict_list.append(d)
print(dict_list)