Python Forum

Full Version: Search Excel column values
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello,

I am using the xlrd library to open a workbook and read its data. I am a newbie and can't figure out how to do a search? For examples on the States worksheet I have some records where value could be CA or TX. My task is to copy all the rows of records where Cell G has CA into one worksheet and then TX into another worksheet. Can someone point me in the right direction? This as far as I got:

import xlrd

path = "C:\\StatesData.xlsx"
inputWorkbook = xlrd.open_workbook(path)
inputWorksheet = inputWorkbook.sheet_by_index(1)
Thanks
John
The cells should be titled. See if your cell g has a header.
You will need an empty list called CA_rows and another called TX_rows.
Read each row, if cell g has CA then append it to CA_rows, if it equals TX then append it to TX_rows.
Here is a great example of using xlrd

Go through the example and try to get further. Post your updated work here if you need more help. You're much more likely to get code correction help than you are to get help writing code.