Pandas DataFrame column another DataFrame when I'm expecting a Series
Question: I have a DataFrame object called "design" which I construct from a DataFrame
object called "df" like so:

    
    
    design = df.loc[year, [DV] + IVs + controls].copy(deep=True)
    

where

    
    
    "DV" = a string
    
    "IVs" = list of strings 
    
    "controls" = list of strings
    

When I then try to access a column of "design" I _usually_ get a Series, as
expected, and can use the .unique() method:

    
    
    design[DV].unique()  
    

^ works fine, usually.

However, _sometimes_ , when I use a different combination of DV, IVs, and
controls, design[DV] is a DataFrame (which doesn't have a .unique() method).
I'm stumped as to why.

Any ideas?

Note: Maybe this is important? Sometimes "controls" is an empty list.
Sometimes the lists contain strings that are unicode.

Thanks in advance!

Edit:

@AndyHayden, here's an example:

design = DataFrame with one column-duplicate ('SPKATH'):

DV = 'LETDIE1'

    
    
    ipdb> design.columns Index([u'LETDIE1', u'SUICIDE1', u'REGION', u'AGE', u'SEX', u'RACE', u'DEGREE', u'INCOME', u'RELIG', u'RELITEN', u'ATTEND', u'POLVIEWS', u'SPKATH', u'SPKCOM', u'SPKATH'], dtype=object)
    

When I call design[DV].unique() I get an error:

    
    
    > /home/misha/.local/lib/python2.7/site-packages/pandas-0.12.0-py2.7-linux-x86_64.‌​egg/pandas/core/frame.py(2088)__getattr__() 2087 raise AttributeError("'%s' object has no attribute '%s'" % -> 2088 (type(self).__name__, name)) 2089 
    
    ipdb> a 
    
    self = <class 'pandas.core.frame.DataFrame'> 
    
    Index: 1530 entries, 1977.0 to 1977.0 
    
    Data columns (total 1 columns): LETDIE1 1530 non-null values dtypes: float64(1) 
    
    name = unique
    


Answer: One situation where this occurs is if you have **duplicate** columns, that is,
DV is in IVs or controls. For example:

    
    
    In [11]: df = pd.DataFrame([[1, 2, 3], [4, 5, 6]], columns=list('ABC'))
    
    In [12]: df_a = df.loc[:, list('ABB')]
    
    In [13]: df_a
    Out[13]:
       A  B  B
    0  1  2  2
    1  4  5  5
    
    In [14]: df_a['A']  # a Series
    Out[14]:
    0    1
    1    4
    Name: A, dtype: int64
    
    In [15]: df_a['B']  # a DataFrame
    Out[15]:
       B  B
    0  2  2
    1  5  5
    

One way to get around this is to select by position:

    
    
    In [16]: df_a.iloc[:, 1]  # always a Series
    Out[16]:
    0    2
    1    5
    Name: B, dtype: int64
    

