I have a pandas dataframe with multiple rows and columns filled with types and values. All are strings. I want to write a function that conditions: 1) which type I search (column 1) 2) a first value (column 2) 3) a second, consecutive value (in the next row of column 2)
I manage to write a function that searches one value of one type as below, but how do I add the second type? I think it might be with help of df.shift(axis=0), but I do not know how to combine that command with a conditional search.
import pandas as pd
d = {'type': ['wordclass', 'wordclass', 'wordclass', 'wordclass', 'wordclass', 'wordclass',
'english', 'english', 'english', 'english', 'english', 'english'],
'values': ['dem', 'noun', 'cop', 'det', 'dem', 'noun', 'this', 'tree', 'is', 'a', 'good', 'tree']}
df = pd.DataFrame(data=d)
print(df)
tiername = 'wordclass'
v1 = 'dem'
v2 = 'noun'
def search_single_tier(tiername, v1):
searchoutput = df[df['type'].str.contains(tiername) & df['values'].str.match(v1)]
return searchoutput
x = search_single_tier(tiername, v1)
print(x)```