Python Forum
Find string return different string
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Find string return different string
#1
Hello,

I need to find the string inside TFile, and once the string is located I need to return the string 9 cells below it. TFile contains only one column. I'm not sure if I'm on the right path here, or totally off. I'm not sure how to go about what to add under if StringFound. I just know if string is found return string 9 cells down.

TFile=pd.read_excel(Train, usecols="B")

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 FindXlCell(String):
     StringFound = FindXlCell(String, TFile.iter_rows(min_col=1, max_col=1))
     if StringFound:
Reply
#2
incomplete code -- Cannot be run as presented.
Reply
#3
A few other things:

1. Your indentation is a mess, so Python should be raising an IndentationError about it.

2. On line 6, it looks like you're trying to call your function recursively and that doesn't make sense because you'd just end up in infinite recursion. That won't happen anyway, because you're trying to call the function with two arguments but the signature says it only takes one (line 5). Python doesn't let you overload functions in the same way that say, Java does.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  string to float conversion fails PetarPetrenko 10 994 Feb-29-2024, 04:20 PM
Last Post: deanhystad
  Help with extracting characters from string valentino1337 2 457 Feb-19-2024, 01:17 PM
Last Post: Pedroski55
  String to Number in Python Godjuned 3 1,352 Nov-17-2022, 07:22 AM
Last Post: Godjuned
  number to string Ali_ 1 1,278 Mar-31-2022, 11:22 AM
Last Post: ndc85430
  position of shortest string Ali_ 2 1,471 Mar-17-2022, 03:48 PM
Last Post: DeaD_EyE
  Count occurences in a string and add to a list using loops Leyo 4 1,679 Mar-11-2022, 03:52 PM
Last Post: Leyo
  Finding how many times substring is in a string using re module ranbarr 4 2,947 May-21-2021, 06:14 PM
Last Post: nilamo
  Checking if string starts the same but end differently using re module ranbarr 1 1,676 May-20-2021, 06:23 PM
Last Post: Gribouillis
  I need help writing this code for string properties and methods hannah71605 4 3,109 Mar-22-2021, 12:36 PM
Last Post: menator01
  Searching for parts of a string or word Ulumulu 8 3,720 Mar-15-2021, 07:02 PM
Last Post: Ulumulu

Forum Jump:

User Panel Messages

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