python – 熊猫:无法导入名称adjoin
作者:互联网
来自Wes:
def side_by_side(*objs, **kwds):
from pandas.core.common import adjoin
space = kwds.get('space', 4)
reprs = [repr(obj).split('\n') for obj in objs]
print adjoin(space, *reprs)
申请如下:
import pandas as pd
df1 = pd.DataFrame(np.random.rand(10,3))
df2 = pd.DataFrame(np.random.rand(10,3))
side_by_side(df1, df2)
引发错误:
ImportError Traceback (most recent call last)
<ipython-input-25-2674cd8a228c> in <module>()
3
4
----> 5 side_by_side(df1, df2)
<ipython-input-24-9f441ebc9cb3> in side_by_side(*objs, **kwds)
1 def side_by_side(*objs, **kwds):
----> 2 from pandas.core.common import adjoin
3 space = kwds.get('space', 4)
4 reprs = [repr(obj).split('\n') for obj in objs]
5 print adjoin(space, *reprs)
ImportError: cannot import name adjoin
解决方法:
我想这个函数已被移到pandas.formats.printing:
In [69]: from pandas.formats.printing import adjoin
更新:as already mentioned by @debo for Pandas 0.20.0使用:
from pandas.io.formats.printing import adjoin
标签:python,pandas,pretty-print 来源: https://codeday.me/bug/20190829/1757419.html