我尝试了以下陈述:
import pandas as pd
df = pd.DataFrame(index=[i for i in range(5)])
df.columns = ["res"+str(i) for i in range(5)]
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python35\lib\site-packages\pandas\core\generic.py", line 5080, in __setattr__
return object.__setattr__(self, name, value)
File "pandas\_libs\properties.pyx", line 69, in pandas._libs.properties.AxisProperty.__set__
File "C:\Python35\lib\site-packages\pandas\core\generic.py", line 638, in _set_axis
self._data.set_axis(axis, labels)
File "C:\Python35\lib\site-packages\pandas\core\internals\managers.py", line 155, in set_axis
'values have {new} elements'.format(old=old_len, new=new_len))
ValueError: Length mismatch: Expected axis has 0 elements, new values have 5 elements
不明白这是什么原因。如果我有索引,那么为什么没有添加该列?
POPMUISE
LEATH
相关分类