pydata/pandas — pull request #4805 by adgaudio (2013-09-10 18:58:31+00:00)
Title: ENH: Series constructor converts dicts with tuples in keys to MultiIndex

Hi,

I'd love for Series (and DataFrame) initialized with a dict to automatically create the MultiIndex. See below example.

Desired Result:

In [1]: pandas.Series({('a', 'b'): 1, ('a', 'a'): 0, ('a', 'c'): 2, ('b', 'a'): 3, ('b', 'b'): 4})
Out[1]:
a a 0
b 1
c 2
b a 3
b 4
dtype: int64

In [2]:

Current result:

In [1]: pandas.Series({('a', 'b'): 1, ('a', 'a'): 0, ('a', 'c'): 2, ('b', 'a'): 3, ('b', 'b'): 4})
Out[1]:
(a, a) 0
(a, b) 1
(a, c) 2
(b, a) 3
(b, b) 4
dtype: int64

In [2]:

Is this something I can go ahead and update tests for? It seems like we should have it.

Also, what are your thoughts about adding this to the DataFrame constructor as well?

Thanks,
Alex