Python for loop over two lists for all the pairs
<p>I have a dataframe with date, id - I need to pull out each date and id combination and create a new dataframe.</p>

<pre><code>  date           id
2016-05-13       abc
2016-05-13       pqr
2016-05-14       abc
2016-05-14       pqr

ids = list(sorted(set(df['id'])))
Out: ['abc','pqr']

dates = list(sorted(set(df[df.id == ids[i]]['date'])))
Out: ['2016-05-13','2016-05-14']

for i in range(0,len(ids)):
    df2 = df[(df.date == dates[i]) &amp; (df.id == id[i])]
</code></pre>

<p>The above code is resulting the output (<code>df2</code>) for relative index values only (First date, First Id &amp; Second date, Second Id), but I need the output for all the pairs. Please let me know what to change in the loop?</p>

<p>Create a new dataframe with each <code>id</code> in columns and each <code>date</code> in rows.  You can fill it in later.</p>

<pre><code>pd.DataFrame([], set(df.date), set(df.id))
</code></pre>

<p><a href="http://i.stack.imgur.com/ig5Xe.png" rel="nofollow"><img src="http://i.stack.imgur.com/ig5Xe.png" alt="enter image description here"></a></p>

<hr>

<p>if you just want the list of combinations</p>

<pre><code>pd.MultiIndex.from_product([set(df.id), set(df.date)]).tolist()

[('pqr', '2016-05-14'),
 ('pqr', '2016-05-13'),
 ('abc', '2016-05-14'),
 ('abc', '2016-05-13')]
</code></pre>

python pandas for-loop iteration