I have a table in .csv which contains some random messages:
id,msg
2,start
1,bot
1,run
2,san
I want to get only rows which match certain condition. I managed to do that, but I want to get all cell values of column - msg which match condition.
My code:
df = pd.read_csv('msgs.csv')
# if id==2 and msg contains letter 'a'
p = df[(df['id'] == 2) & (df['msg'].str.contains('a'))]
print(p)
for row in p:
print(p.iloc[0]['msg'])
When I print(p) my result (which is good) is:
id msg
1 2 start
5 2 san
And I want to have output like this :
start
san
But when I try to do it with iloc I get only first cell value:
start
start
Probably the solution is easy but I don't know how to get it. Thanks in advance.