sample data:
df = pd.DataFrame({'user': ['Mike', 'Jim', 'Bob', 'Jane', 'Alice'],
'income': [45000,55000, 40000, 50000, 42000],
'age' : [20,31,40,35,20]})
I want to be able to select 'user' and 'age' from the current row and the 2 rows above anyone who's name = Alice
here is what I have so far (not sure if any of it is right):
age2 = []
income2 = []
if df("user") in ['Alice']:
age2.append(df.attrib.get("age"))
income2.append(df.attrib.get("user"))
I want to have
age income
35 50000
40 40000
31 55000