我有包含 3 列的数据框数据 - 日期、段和指标。我正在执行以下操作:
data = pandas.read_csv("Filename.csv")
ave = data.groupby('Segment').mean() #works
ave = data.groupby('Segment').median() #gives error
ave['median'] = data.groupby('Segment').median()
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "/usr/lib/pymodules/python2.7/pandas/core/frame.py", line 1453, in __setitem__
self._set_item(key, value)
File "/usr/lib/pymodules/python2.7/pandas/core/frame.py", line 1488, in _set_item
NDFrame._set_item(self, key, value)
File "/usr/lib/pymodules/python2.7/pandas/core/generic.py", line 301, in _set_item
self._data.set(key, value)
File "/usr/lib/pymodules/python2.7/pandas/core/internals.py", line 616, in set
assert(value.shape[1:] == self.shape[1:])
AssertionError