Q:

Too many values to unpack (expected 2) [list]

I have a dataset that contain 4 columns:
"Date", "Num_week", "Calendar"
df.head() looks like:
    Date    Num_week    Calendar
412 2012-01-01  1      (2012, 1)
413 2012-01-02  2      (2012, 1)
414 2012-01-03  2      (2012, 1)
415 2012-01-04  2      (2012, 1)
416 2012-01-05  2      (2012, 1)

I sord values in column:  sorted(list(set(date_week['calendar'])))
result:
['(2012, 1)',
 '(2012, 10)',
 '(2012, 11)',
 '(2012, 12)',
 '(2012, 2)',
 '(2012, 3)', etc.

And I try to get year and month separeted in loop.
for year, month in list(set(date_week['calendar'])):
    print(year, month)

But get ValueError:
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-168-cf01e0d2888e> in <module>()
----> 1 for year, month in list(set(date_week['calendar'])):
      2     print(year, month)

ValueError: too many values to unpack (expected 2)

I've already tried use .items() and get wrong result.
Could you help me to deal with this problem?

A:

Problem is there are no tuples, but string repr of tuples, so need converting first:
import ast
date_week['Calendar'] = date_week['Calendar'].apply(ast.literal_eval)

So possible use your solution or alternative:
for year, month in date_week['Calendar'].unique():
    print(year, month)
    2012 1

EDIT: Alternative solution with Series.str.findall and converting to tuples:
date_week['Calendar'] = date_week['Calendar'].str.findall('\d+').apply(tuple)
print (date_week)
           Date  Num_week   Calendar
412  2012-01-01         1  (2012, 1)
413  2012-01-02         2  (2012, 1)
414  2012-01-03         2  (2012, 1)
415  2012-01-04         2  (2012, 1)
416  2012-01-05         2  (2012, 1)

