熊猫:不能导入名称邻接

时间:2016-07-02 05:50:22

标签: python pandas pretty-print

来自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

2 个答案:

答案 0 :(得分:4)

我想这个功能已经移到了pandas.formats.printing

In [69]: from pandas.formats.printing import adjoin

更新as already mentioned by @debo适用于Pandas 0.20.0+使用:

from pandas.io.formats.printing import adjoin

答案 1 :(得分:1)

更改了pandas版本0.20。*

from pandas.io.formats.printing import adjoin