Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/354.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.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_Loops_For Loop_Pandas - Fatal编程技术网

Python 使用列遍历字典

Python 使用列遍历字典,python,loops,for-loop,pandas,Python,Loops,For Loop,Pandas,我有以下代码,使用Pandas和for循环迭代DF的索引,并生成字典中每一行的字符串: for i in zip(d['Series'].ix[i], d['Working Title'].ix[i], df['Time'].ix[i], d['Created By'].ix[i], t['strdate'].ix[i]): ... event = { ... 'summary': d['Series'].ix[i], ... 'loca

我有以下代码,使用Pandas和for循环迭代DF的索引,并生成字典中每一行的字符串:

 for i in zip(d['Series'].ix[i], d['Working Title'].ix[i], df['Time'].ix[i], d['Created By'].ix[i], t['strdate'].ix[i]):
...     event = {
...             'summary': d['Series'].ix[i],
...             'location': '8965 Lindblade St.',
...             'description': d['Working Title'].ix[i] + ' at ' + df['Time'].ix[i] + ' by ' + d['Created By'].ix[i],
...              'start': {
...                      'date': t['strdate'].ix[i],
...                     'timeZone': 'America/Los_Angeles',
...                     },
...             'end': {
...                     'date': t['strdate'].ix[i],
...                     'timeZone': 'America/Los_Angeles',
...                     }
...             }
这样做不好吗?有没有更好的方法可以动态创建dictionary对象、事件并通过for循环函数传递它

谢谢!
Chris

这看起来相当复杂-在循环的每次迭代中,您都会覆盖
事件
字典?我很确定这段代码不会运行,因为
I
是for循环的变量,并且
zip(…)
中有一些索引。我认为您应该尝试指定您的预期结果,然后有人可能会帮助您。我想知道是否有一种方法可以遍历Pandas中的列,生成一个带有迭代变量的字典来代替该字典。我甚至不知道这叫什么,哈哈。即使那会被称为是有帮助的…@chris,这听起来仍然没有帮助。。如果您想在DF中添加一些数据示例和预期结果,可以尝试了解您想要实现的目标。但这并不是一个令人困惑且不起作用的代码示例。还有一个问题让我重新编辑一下…@chrissc