python - See if item in each row of pandas series -
i have pandas series following data:
2015-07-24 ['business', 'corporate'] 2015-07-24 ['business', 'corporate'] 2015-07-08 ['commentary', 'world'] 2015-07-05 ['issues', 'just cause'] 2015-06-15 ['business'] 2015-04-11 ['business', 'economy'] 2015-03-24 ['food & drink'] 2015-02-24 ['commentary', 'japan'] 2015-02-19 ['business', 'financial markets'] 2015-01-05 ['national', '70 years of peace , prosperity'] 2014-11-06 ['national'] 2014-10-31 ['business', 'financial markets'] 2014-10-20 ['business'] 2014-09-22 ['business', 'economy'] 2014-09-02 ['business', 'corporate'] 2014-08-08 ['business', 'financial markets'] 2014-07-18 ['business', 'financial markets', 'tse data & ... 2014-07-15 ['business', 'economy'] 2014-07-10 ['national'] 2013-12-16 ['business', 'financial markets'] 2013-10-29 ['national'] 2013-10-15 ['national'] 2013-10-06 ['business', 'financial markets'] 2013-06-25 ['business', 'financial markets'] 2013-06-17 ['editorials'] 2013-05-21 ['voices', 'views street'] 2013-05-15 ['business', 'financial markets'] 2013-05-03 ['national'] 2013-03-07 ['business', 'financial markets'] 2013-02-10 ['business', 'economy'] name: tags, length: 216, dtype: object
is there way boolean array telling me whether each list contains either "business" or "food & drink"?
using set
df.tags.apply(set) & set(['business', 'food & drink']) 2015-07-24 true 2015-07-24 true 2015-07-08 false 2015-07-05 false 2015-06-15 true 2015-04-11 true 2015-03-24 true 2015-02-24 false 2015-02-19 true 2015-01-05 false 2014-11-06 false 2014-10-31 true 2014-10-20 true 2014-09-22 true 2014-09-02 true 2014-08-08 true 2014-07-18 true 2014-07-15 true 2014-07-10 false 2013-12-16 true 2013-10-29 false 2013-10-15 false 2013-10-06 true 2013-06-25 true 2013-06-17 false 2013-05-21 false 2013-05-15 true 2013-05-03 false 2013-03-07 true 2013-02-10 true name: tags, dtype: bool
look @ results side side
df.assign(i=df.tags.apply(set) & set(['business', 'food & drink'])) tags 2015-07-24 [business, corporate] true 2015-07-24 [business, corporate] true 2015-07-08 [commentary, world] false 2015-07-05 [issues, cause] false 2015-06-15 [business] true 2015-04-11 [business, economy] true 2015-03-24 [food & drink] true 2015-02-24 [commentary, japan] false 2015-02-19 [business, financial markets] true 2015-01-05 [national, 70 years of peace , prosperity] false 2014-11-06 [national] false 2014-10-31 [business, financial markets] true 2014-10-20 [business] true 2014-09-22 [business, economy] true 2014-09-02 [business, corporate] true 2014-08-08 [business, financial markets] true 2014-07-18 [business, financial markets, tse data &] true 2014-07-15 [business, economy] true 2014-07-10 [national] false 2013-12-16 [business, financial markets] true 2013-10-29 [national] false 2013-10-15 [national] false 2013-10-06 [business, financial markets] true 2013-06-25 [business, financial markets] true 2013-06-17 [editorials] false 2013-05-21 [voices, views street] false 2013-05-15 [business, financial markets] true 2013-05-03 [national] false 2013-03-07 [business, financial markets] true 2013-02-10 [business, economy] true
Comments
Post a Comment