diff --git a/pandas/core/frame.py b/pandas/core/frame.py index bb490a92d..1854cec34 100644 --- a/pandas/core/frame.py +++ b/pandas/core/frame.py @@ -1429,6 +1429,11 @@ def _getitem_multilevel(self, key): new_values = self.values[:, loc] result = DataFrame(new_values, index=self.index, columns=result_columns) + if len(result.columns) == 1: + top = result.columns[0] + if (type(top) == str and top == '' or + type(top) == tuple and top[0] == ''): + result = Series(result[''], index=self.index, name=key) return result else: return self._get_item_cache(key) diff --git a/pandas/core/generic.py b/pandas/core/generic.py index 16ac9d78d..86f3ccbcb 100644 --- a/pandas/core/generic.py +++ b/pandas/core/generic.py @@ -302,7 +302,21 @@ def __delitem__(self, key): """ Delete item """ - self._data.delete(key) + deleted = False + if key not in self.columns: + # If column labels are tuples, allow shorthand to delete + # all columns whose first len(key) elements match key: + if not isinstance(key,tuple): + key = (key,) + for col in self.columns: + if isinstance(col,tuple) and col[:len(key)] == key: + del self[col] + deleted = True + if not deleted: + # If the above loop ran and didn't delete anything because + # there was no match, this call should raise the appropriate + # exception: + self._data.delete(key) try: del self._item_cache[key]