我正在尝试通过股票代码的名称为数据框建立索引,但是出现错误:
df = data
df = df.fillna(method='ffill').dropna().T
df.index= symbols
这会导致以下错误:
----------------------------------------------------------------------- ----
ValueError Traceback (most recent call last)
<ipython-input-11-fc492c1217e1> in <module>
1 df = data
2 df = df.fillna(method='ffill').dropna().T
----> 3 df.index= symbols # change index to symbol names
/opt/miniconda3/lib/python3.6/site-packages/pandas/core/generic.py in __setattr__(self, name, value)
4387 try:
4388 object.__getattribute__(self, name)
-> 4389 return object.__setattr__(self, name, value)
4390 except AttributeError:
4391 pass
pandas/_libs/properties.pyx in
pandas._libs.properties.AxisProperty.__set__()
/opt/miniconda3/lib/python3.6/site-packages/pandas/core/generic.py in _set_axis(self, axis, labels)
644
645 def _set_axis(self, axis, labels):
--> 646 self._data.set_axis(axis, labels)
647 self._clear_item_cache()
648
/opt/miniconda3/lib/python3.6/site-packages/pandas/core/internals.py in set_axis(self, axis, new_labels)
3321 raise ValueError(
3322 'Length mismatch: Expected axis has {old} elements, new '
-> 3323 'values have {new} elements'.format(old=old_len, new=new_len))
3324
3325 self.axes[axis] = new_labels
ValueError: Length mismatch: Expected axis has 18 elements, new values have 19 elements
我不知道如何解决长度不匹配的错误,希望能提供一些帮助。