從此開始。
dfm = pd.DataFrame({'A' : ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo']*2,
'B' : ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three']*2})
A B
0 foo one
1 bar one
2 foo two
3 bar three
4 foo two
5 bar two
6 foo one
7 foo three
8 foo one
9 bar one
10 foo two
11 bar three
12 foo two
13 bar two
14 foo one
15 foo three
Usage:
Change "4" to "10", use [i] to get the slices.
np.random.seed(32) # for reproducible results.
np.array_split(dfm.reindex(np.random.permutation(dfm.index)),4)[1]
A B
2 foo two
5 bar two
10 foo two
12 foo two
np.array_split(dfm.reindex(np.random.permutation(dfm.index)),4)[3]
A B
13 foo two
11 bar three
0 foo one
7 foo three
這已經得到了解答:剛結合[這](http://stackoverflow.com/a/17315875/2077270)與[這裏](http://stackoverflow.com/a/15772356/2077270 ) – dermen