[英]How do I filter for rows in a Pandas dataframe based on a column that has list as values?
I have a Pandas dataframe where one of the columns stores lists of string literals. 我有一个Pandas数据框,其中的一列存储字符串文字列表。 For example, my data looks like the following.
例如,我的数据如下所示。
field1, field2
x1, ['tag1', 'tag2']
x2, ['tag1', 'tag3']
I want to get only the records in this dataframe whose field2
list contains tag1
or tag2
. 我只想获取此dataframe中其
field2
列表包含tag1
或tag2
。 So, in the example above, only the record where field1=x1
should be returned. 因此,在上面的示例中,仅应返回其中
field1=x1
的记录。
How can I do this filtering on a Pandas dataframe? 如何在Pandas数据框上执行此过滤?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.