Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Search Excel column values
#1
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
Reply
#2
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Get an average of the unique values of a column with group by condition and assign it klllmmm 0 220 Feb-17-2024, 05:53 PM
Last Post: klllmmm
  Converting column of values into muliple columns of counts highland44 0 205 Feb-01-2024, 12:48 AM
Last Post: highland44
  Search Excel File with a list of values huzzug 4 1,147 Nov-03-2023, 05:35 PM
Last Post: huzzug
  Search Outlook Inbox for set of values cubangt 1 975 Jun-28-2023, 09:29 PM
Last Post: cubangt
  PowerBI: Using Python Regex to look for values in column MarcusR44 1 920 Oct-14-2022, 01:03 PM
Last Post: ibreeden
  How to combine multiple column values into 1? cubangt 15 2,630 Aug-11-2022, 08:25 PM
Last Post: cubangt
  How to format Excel column with comma? dee 0 1,337 Jun-13-2022, 10:11 PM
Last Post: dee
  Trying to use 2 values from excel in my script but getting error.. cubangt 3 1,624 May-11-2022, 07:12 AM
Last Post: normanwolf
  Creating a numpy array from specific values of a spreadsheet column JulianZ 0 1,077 Apr-19-2022, 07:36 AM
Last Post: JulianZ
  How to split file by same values from column from imported CSV file? Paqqno 5 2,705 Mar-24-2022, 05:25 PM
Last Post: Paqqno

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020