Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.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_List_Pandas_Series - Fatal编程技术网

Python 创建新列表并基于系列的值进行填充

Python 创建新列表并基于系列的值进行填充,python,list,pandas,series,Python,List,Pandas,Series,我正在尝试创建一个for循环,循环遍历pandas系列,ageNew,根据pandas系列的内容填充一个列表,label 这是我拥有的输出错误的代码: 在: 使用item()时,需要为station示例传入两个参数: for k,v in dct.items(): print(k, v) 为了效率和简洁,请使用向量运算而不是循环 label = (age_new > 100).astype(int).tolist() 可以使用.values而不是.items()仅获取值: fo

我正在尝试创建一个for循环,循环遍历pandas系列,
ageNew
,根据pandas系列的内容填充一个列表,
label

这是我拥有的输出错误的代码:

在:

使用
item()
时,需要为station示例传入两个参数:

for k,v in dct.items():
    print(k, v)

为了效率和简洁,请使用向量运算而不是循环

label = (age_new > 100).astype(int).tolist()

可以使用.values而不是.items()仅获取值:

for v in dct.values:
    if v <= 100:
        ...
dct中v的
值:

如果v
表示k,v表示age\u new.items()
不要使用camalcase,您可以在ageNew.values:
表示i。更高性能的版本:
(age\u new.values>100)。astype(int)。tolist()
哦,这很酷,只是出于好奇,向量操作如何处理非二进制值,即标签可以等于0、1或2。是这样的:
((新时代7)).astype(int).tolist()
差不多了!使用逐位
运算符
&
而不是
&
<代码>&&不是有效的python运算符。类似地,按位
运算符是
|
,而不是输出
KeyError:218
运算符:如果i
不是一个系列的函数,则执行以下操作:
。这不是一本字典。
label = (age_new > 100).astype(int).tolist()
for v in dct.values:
    if v <= 100:
        ...