I'm trying to filter for something, but if there are no results I want to get a 'zero' column rather than a blank df. I need this because it gets fed into a summation equation further down and having it blank screws it all up. See:
>>> df
id name price qty
0001 'bob' 100 4
0001 'bob' 67 5
0001 'bob' 63 6
0002 'jack' 67 3
0002 'jack' 98 7
0002 'jack' 90 12
0003 'jack' 60 3
0003 'jack' 78 7
0003 'rose' 87 15
df_jim_frank_qty = df[df['name'].isin(['jim','frank'])]
df_jim_frank_qty
>>> df_jim_frank_qty
id name price qty
I need it to look like this:
>>> df_jim_frank_qty
id name price qty
NaN NaN NaN 0
I suspect I have to put some kind of IF argument in there and manually create that, but I'm not sure how. Any thoughts?
Thanks!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…