Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/317.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 熊猫:如何按值筛选列列表?_Python_Pandas_Dataframe - Fatal编程技术网

Python 熊猫:如何按值筛选列列表?

Python 熊猫:如何按值筛选列列表?,python,pandas,dataframe,Python,Pandas,Dataframe,我有一个熊猫数据框,它在其中一列中存储列表: >>> import pandas as pd >>> d = [{'name': 'john', 'properties': ['a','b']}, ... {'name': 'mary', 'properties': ['a','c']}] >>> df = pd.DataFrame(d) >>> df name properties 0 john

我有一个熊猫数据框,它在其中一列中存储列表:

>>> import pandas as pd
>>> d = [{'name': 'john', 'properties': ['a','b']},
...      {'name': 'mary', 'properties': ['a','c']}]
>>> df = pd.DataFrame(d)
>>> df
   name properties
0  john     [a, b]
1  mary     [a, c]
如何按列表成员资格进行筛选?例如,列出在其属性列中具有“c”的所有行

我知道我可以分解属性列:

但我更愿意把它列为一个列表。

你可以使用地图

df.explode('properties')
df[df.properties.map(lambda x: 'c' in x)]