Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/361.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 list()与ipython笔记本中的另一个操作嵌套时删除整个列表_Python_List_Ipython - Fatal编程技术网

python list()与ipython笔记本中的另一个操作嵌套时删除整个列表

python list()与ipython笔记本中的另一个操作嵌套时删除整个列表,python,list,ipython,Python,List,Ipython,我试图从panda数据框中获取列标题列表。我还想删除列表中一个不需要的元素。我尝试了下面的代码,这很有效 features_list = list(data_panda.columns.values) features_list.remove('email_address') features_list 输出:生成列表 但当我尝试在下面的单行中这样做时,我没有得到任何输出 features_list_1 = list(data_panda.columns.values).remove('ema

我试图从panda数据框中获取列标题列表。我还想删除列表中一个不需要的元素。我尝试了下面的代码,这很有效

features_list = list(data_panda.columns.values)
features_list.remove('email_address')
features_list
输出:生成列表

但当我尝试在下面的单行中这样做时,我没有得到任何输出

features_list_1 = list(data_panda.columns.values).remove('email_address')
features_list_1
输出:无

屏幕截图

为什么?

我正在Anaconda中使用Py2环境

.remove()
修改原始列表,它不返回任何内容。这就是为什么
features\u list\u 1
为None,因为这是不返回任何内容时的默认值


如果要在一行中完成此操作,则不能使用
.remove()
,而是使用列表创建一个新列表

features_list = [x for x in data_panda.columns.values if x != 'email_address']
但与
remove
不同,这将删除所有出现的
'email\u address'
,而
remove
仅删除第一个


以下内容将像一行的
.remove()
(仅删除第一个匹配项)一样工作,而不使用分号(因为这只是作弊)。但是请,请不要这样做。。。用正常的方式写

features_list = (lambda y=set(): [x for x in data_panda.columns.values if y or (x != 'email_address' or y.add(0))])()
.remove()
修改原始列表,它不返回任何内容。这就是为什么
features\u list\u 1
为None,因为这是不返回任何内容时的默认值


如果要在一行中完成此操作,则不能使用
.remove()
,而是使用列表创建一个新列表

features_list = [x for x in data_panda.columns.values if x != 'email_address']
但与
remove
不同,这将删除所有出现的
'email\u address'
,而
remove
仅删除第一个


以下内容将像一行的
.remove()
(仅删除第一个匹配项)一样工作,而不使用分号(因为这只是作弊)。但是请,请不要这样做。。。用正常的方式写

features_list = (lambda y=set(): [x for x in data_panda.columns.values if y or (x != 'email_address' or y.add(0))])()

因为
remove
在适当的位置工作并返回
None
。因为
remove
在适当的位置工作并返回
None