0

I have the following code using Pandas and a for loop to iterate through the index of the DF and produce strings of each row in a dictionary:

 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',
...                     }
...             }

Is this a bad way of doing this? Is there a better way to be able to dynamically create the dictionary object, event, and pass it through a for loop function?

Thanks! Chris

Julien
  • 13,986
  • 5
  • 29
  • 53
cmagorian
  • 25
  • 3
  • that looks quite complex - and you are overwriting your `event` dictionary on every iteration of the loop? I'm pretty sure this code won't even run, with `i` being the variable of the for-loop AND some index in the `zip(...)`. I think you should try to specify what your expected outcome is, and then somebody might be able to help you. – chris-sc Nov 18 '15 at 06:20
  • I am wondering if there is a way to iterate through columns in Pandas producing a dictionary with the iterated variables in place of that dictionary. I am not even sure what this is called haha. Even what that would be called would be helpful...@chris-sc – cmagorian Nov 18 '15 at 22:02
  • that still doesn't sound helpful.. If you would add some example of your data in the DF and your expected outcome, one could try to understand what you want to achieve. But not with this confusing and not working code example. Also have a look at https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples – chris-sc Nov 19 '15 at 09:53
  • let me re edit the question...@chris-sc – cmagorian Nov 19 '15 at 23:07

0 Answers0