Python Forum
Match string return different cell string - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: Match string return different cell string (/thread-28472.html)



Match string return different cell string - Kristenl2784 - Jul-20-2020

Hello,

Is there a way to search for a string, and once it's found return the value thats 9 cells below it?

This code reads in TFile only column B data. Then it reads in TDetail looks at cell A1 shortens the word, and then makes it a string example AA1150. Then I want to search for TDetail (example AA1150) inside TFile, and once that string is located return the value that is 9 cells below it.

TFile = Row B tons of data TDetail= string example AA1150

Search TTFile for TTDetail once found return value 9 cells below it.

TFile=pd.read_excel(TF, usecols="B")
  
TDetail=pd.read_excel(input_file, usecols="A",nrows=1,header=None,squeeze=True).str.slice(start=28,stop=-2).to_string(index=False).strip()

result=TFile['Name'].str.contains(TDetail)