This question is related to the following thread:
How would you zip an unknown number of lists in Python?
I'm working with a dataframe (merged_data) that has two fields ("campaignName" and "creativeName") where I'd like to produce a list of every pair-wise combination of values within the two fields. Based on the guidance above, here's the code that I thought would do it:
print varlist print merged_data[varlist] combo = zip(*merged_data[varlist]) print combo combo2 = zip(merged_data[varlist[0]], merged_data[varlist[1]]) print combo2 But here are the results of the two zip commands (which I had thought would produce an identical list of tuples):
['campaignName', 'creativeName']
campaignName creativeName 0 MMedia Whatsapp 12-24-14 Pic1-Angle1-300x250 1 MMedia Whatsapp 12-24-14 Pic1-Angle1-300x250 ... 89 MMedia Whatsapp 12-25-14 Pic4-Angle1-300x250 [90 rows x 2 columns] [('c', 'c'), ('a', 'r'), ('m', 'e'), ('p', 'a'), ('a', 't'), ('i', 'i'), ('g', 'v'), ('n', 'e'), ('N', 'N'), ('a', 'a'), ('m', 'm'), ('e', 'e')] [('MMedia Whatsapp 12-24-14', 'Pic1-Angle1-300x250'), ('MMedia Whatsapp 12-24-14', 'Pic1-Angle1-300x250'), ('MMedia Whatsapp 12-24-14', 'Pic1-Angle1-300x250'), ..., ('MMedia Whatsapp 12-25-14', 'Pic4-Angle1-300x250')] Any idea what's going on? Obviously, in the first case it's treating ['campaignName', 'creativeName'] like a string of letters and in the case of the second, it's treating them like fields in the data frame and then looking at the values inside.
Appreciate any and all assistance here. Thanks in advance!