我有现有的代码,我发现使用 pandas 数据帧来存储其他数据帧很有用,这在 pandas 0.10.1 中运行良好,但不再可能使用 pandas 0.12.0 显示此类数据帧。然而,仍然可以在这些数据帧中存储和检索。这是一个错误还是我做错了什么?
说明性示例:
在 0.10.1 中工作:
>>> import pandas as pd
>>> pd.__version__
'0.10.1'
>>> df1 = pd.DataFrame({'a':[1, 2, 3], 'b':[3, 4, 5]})
>>> df2 = pd.DataFrame([df1, df1+10])
>>> df2[0][0]
a b
0 1 3
1 2 4
2 3 5
>>> df2[0][1]
a b
0 11 13
1 12 14
2 13 15
>>> df2
0
0 [a, b]
1 [a, b]
>>>
并且不能在 pandas 0.12.0 中工作:
>>> import pandas as pd
>>> pd.__version__
'0.12.0'
>>> df1 = pd.DataFrame({'a':[1, 2, 3], 'b':[3, 4, 5]})
>>> df2 = pd.DataFrame([df1, df1+10])
>>> df2[0][0]
a b
0 1 3
1 2 4
2 3 5
>>> df2[0][1]
a b
0 11 13
1 12 14
2 13 15
>>> df2
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/data/Local/Envs/latest/lib/python2.7/site-packages/pandas/core/base.py", line 40, in __repr__
return str(self)
File "/home/data/Local/Envs/latest/lib/python2.7/site-packages/pandas/core/base.py", line 20, in __str__
return self.__bytes__()
File "/home/data/Local/Envs/latest/lib/python2.7/site-packages/pandas/core/base.py", line 32, in __bytes__
return self.__unicode__().encode(encoding, 'replace')
File "/home/data/Local/Envs/latest/lib/python2.7/site-packages/pandas/core/frame.py", line 665, in __unicode__
fits_horizontal = self._repr_fits_horizontal_()
File "/home/data/Local/Envs/latest/lib/python2.7/site-packages/pandas/core/frame.py", line 646, in _repr_fits_horizontal_
d.to_string(buf=buf)
File "/home/data/Local/Envs/latest/lib/python2.7/site-packages/pandas/core/frame.py", line 1556, in to_string
formatter.to_string()
File "/home/data/Local/Envs/latest/lib/python2.7/site-packages/pandas/core/format.py", line 294, in to_string
strcols = self._to_str_columns()
File "/home/data/Local/Envs/latest/lib/python2.7/site-packages/pandas/core/format.py", line 247, in _to_str_columns
fmt_values = self._format_col(i)
File "/home/data/Local/Envs/latest/lib/python2.7/site-packages/pandas/core/format.py", line 398, in _format_col
space=self.col_space)
File "/home/data/Local/Envs/latest/lib/python2.7/site-packages/pandas/core/format.py", line 1366, in format_array
return fmt_obj.get_result()
File "/home/data/Local/Envs/latest/lib/python2.7/site-packages/pandas/core/format.py", line 1382, in get_result
fmt_values = self._format_strings()
File "/home/data/Local/Envs/latest/lib/python2.7/site-packages/pandas/core/format.py", line 1418, in _format_strings
fmt_values.append(' %s' % _format(v))
File "/home/data/Local/Envs/latest/lib/python2.7/site-packages/pandas/core/format.py", line 1404, in _format
return '%s' % formatter(x)
File "/home/data/Local/Envs/latest/lib/python2.7/site-packages/pandas/core/format.py", line 1394, in <lambda>
formatter = (lambda x: com.pprint_thing(x, escape_chars=('\t', '\r', '\n'))) \
File "/home/data/Local/Envs/latest/lib/python2.7/site-packages/pandas/core/common.py", line 2059, in pprint_thing
quote_strings=quote_strings)
File "/home/data/Local/Envs/latest/lib/python2.7/site-packages/pandas/core/common.py", line 1963, in _pprint_seq
r.append(pprint_thing(next(s), _nest_lvl + 1, **kwds))
StopIteration