I have a Excelfile which I read with pandas into a dataframe. In this Excelfile are different Key-Value Pairs.
I want to Search for a Key and get the Value (with an row and/or column offset)
This is my code so far (with an example dataframe):
import json
import pandas as pd
def SearchValues(df,str_search,r_offset,c_offset):
print(df[df.eq(str_search).any(1)])
#return Value
data = {'Unnamed: 1': ['', ''],
'Unnamed: 2': ['', 'Key1'],
'Unnamed: 3': ['', ''],
'Unnamed: 4': ['', 'Value1'],
'Unnamed: n': ['Key2', 'Value2'],
}
df = pd.DataFrame(data)
SearchValues(df,'Key1',0,2) #=> result= Value1
SearchValues(df,'Key2',1,0) #=> result= Value2
I struggle in the search function. Is this a possible way? If yes how can I proceed? Or is there any other option. Maybe without dataframe to search directly in the Excelfile.