Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/292.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 如何访问pandas中嵌套ItError的外部for循环索引?_Python_Pandas_Indexing - Fatal编程技术网

Python 如何访问pandas中嵌套ItError的外部for循环索引?

Python 如何访问pandas中嵌套ItError的外部for循环索引?,python,pandas,indexing,Python,Pandas,Indexing,我在最外层循环中遍历一个数据文件,在内层循环中遍历一个序列。我使用iterrows()和items()分别遍历这两个数据结构。从pandas文档来看,“index”名称似乎不能是我声明的变量名 因此,当我在items()循环中时,我访问的“index”是序列中的索引,但我想要数据文件中的索引 最终,我希望能够在迭代时删除特定的行,但我有一个嵌套循环这一事实似乎使事情变得复杂 如有任何建议,将不胜感激。谢谢 我尝试只设置一个布尔值,而不是立即删除行,然后在项目循环之外删除行,但这不起作用 for

我在最外层循环中遍历一个数据文件,在内层循环中遍历一个序列。我使用iterrows()和items()分别遍历这两个数据结构。从pandas文档来看,“index”名称似乎不能是我声明的变量名

因此,当我在items()循环中时,我访问的“index”是序列中的索引,但我想要数据文件中的索引

最终,我希望能够在迭代时删除特定的行,但我有一个嵌套循环这一事实似乎使事情变得复杂

如有任何建议,将不胜感激。谢谢

我尝试只设置一个布尔值,而不是立即删除行,然后在项目循环之外删除行,但这不起作用

for index, row in ldf.iterrows():
   for index, value in comp.items():
        if row['Type'] == index:
            if row['Score'] < value:
                 ldf.drop(index,inplace=True)
对于ldf.iterrows()中的索引行:
对于索引,组件项()中的值:
如果行['Type']==索引:
如果行['Score']<值:
ldf.drop(索引,就地=真)

如果我理解正确,您只需要为两个循环变量使用不同的变量名:

for df_index, row in ldf.iterrows():
   for comp_index, value in comp.items():
        if row['Type'] == comp_index:
            if row['Score'] < value:
                 ldf.drop(df_index, inplace=True)
对于df_索引,ldf.iterrows()中的行:
对于comp_索引,comp.items()中的值:
如果行['Type']==comp_索引:
如果行['Score']<值:
ldf.drop(df_索引,就地=真)

您所说的“索引名不能是您声明的变量名”是什么意思?在外部循环中使用不同的名称-
用于行索引,行…
。哦,就是这样。我犯了错误,我以前试过,我以为失败了。非常感谢。