Jul-22-2020, 08:12 PM
(Jul-22-2020, 07:02 PM)jefsummers Wrote: But that is also the name of your function. In some languages you define your return value by setting it to the function name. That is not true with Python.
Please recognize that by having the return inside an if statement it returns the value only if the first obj.value is equal to the_string. If not, it simply drops to the end of the function and returns nothing.
You could print the value rather than return it (generally bad idea), or build a list of values that match and return that. The latter would bet_file = xl.load_workbook(T) sheet = t_file.worksheets[0] big_string=pd.read_excel(input_file, usecols="A",nrows=1,header=None,squeeze=True).str.slice(start=28,stop=-2).to_string(index=False).strip() def ta(the_string, the_sheet): out_list = [] for cellobj in the_sheet['B2:B10000']: for obj in cellobj: if (obj.value) == the_string: outlist.append(obj.offset(column=2, row=6).value) return out_list #TA = obj.offset I don't know what you are trying to do here print(ta(big_string, sheet))
When I use this it prints out [None]
This is what I had at first. This finds my string and prints it out A1180. Now that I found the string I need to get the string that is 9 cells below the first string same column, and thats where I though offset could be used. Or am I going about this completely wrong?
TrainFile = xl.load_workbook(Train) TrainFileSheet = TrainFile.worksheets[0] String=pd.read_excel(input_file, usecols="A",nrows=1,header=None,squeeze=True).str.slice(start=28,stop=-2).to_string(index=False).strip() for cellObj in TrainFileSheet['B2:B10000']: for obj in cellObj: if (obj.value) == String: TA = obj.value print(TA) A1180