问题
From 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)
Apply below:
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)
Throws error:
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
回答1:
I guess this function has been moved to pandas.formats.printing
:
In [69]: from pandas.formats.printing import adjoin
UPDATE: as already mentioned by @debo for Pandas 0.20.0+ use:
from pandas.io.formats.printing import adjoin
回答2:
Changed for pandas version 0.20.*
from pandas.io.formats.printing import adjoin
来源:https://stackoverflow.com/questions/38156965/pandas-cannot-import-name-adjoin