用途
np.array_split:
Docstring:Split an array into multiple sub-arrays.Please refer to the ``split`` documentation. The only differencebetween these functions is that ``array_split`` allows`indices_or_sections` to be an integer that does *not* equallydivide the axis.
In [1]: import pandas as pdIn [2]: df = pd.Dataframe({'A' : ['foo', 'bar', 'foo', 'bar', ...: 'foo', 'bar', 'foo', 'foo'], ...: 'B' : ['one', 'one', 'two', 'three', ...: 'two', 'two', 'one', 'three'], ...: 'C' : randn(8), 'D' : randn(8)})In [3]: print df A B C D0 foo one -0.174067 -0.6085791 bar one -0.860386 -1.2105182 foo two 0.614102 1.6898373 bar three -0.284792 -1.0711604 foo two 0.843610 0.8037125 bar two -1.514722 0.8708616 foo one 0.131529 -0.9681517 foo three -1.002946 -0.257468In [4]: import numpy as npIn [5]: np.array_split(df, 3)Out[5]: [ A B C D0 foo one -0.174067 -0.6085791 bar one -0.860386 -1.2105182 foo two 0.614102 1.689837, A B C D3 bar three -0.284792 -1.0711604 foo two 0.843610 0.8037125 bar two -1.514722 0.870861, A B C D6 foo one 0.131529 -0.9681517 foo three -1.002946 -0.257468]


