我有什么:
Series_dataframe =
的Pandas数据框0 {‘a’:0, ‘b’:’one’, ‘c’:0}
1 {‘a’:1, ‘b’:’two’, ‘c’:1}
2 {‘a’:2, ‘b’:’three’, ‘c’:2}
3 {‘a’:3, ‘b’:’four; ‘c’:3}
4 {‘a’:4, ‘b’:’five’, ‘c’:4}
5 {‘a’:5, ‘b’:’six’, ‘c’:5}
6 {‘a’:6, ‘b’:’seven’, ‘c’:6}
7 {‘a’:7, ‘b’:’eight’, ‘c’:7}
8 {‘a’:8, ‘b’:’nine’, ‘c’:8}
9 {‘a’:9, ‘b’:’ten’, ‘c’:9}
10 {‘a’:10, ‘b’:’eleven’, ‘c’:10}
如果我输入了多个分区......例如,如果partition = 5:
我想要的:一个数据框,其中的值是字典列表
Pandas数据框
0 [{‘a’:0, ‘b’:’one’, ‘c’:0}, {‘a’:1, ‘b’:’two’, ‘c’:1}, {‘a’:2, ‘b’:’three’, ‘c’:2}, {‘a’:3, ‘b’:’four; ‘c’:3}, {‘a’:4, ‘b’:’five’, ‘c’:4}]
1 [{‘a’:5, ‘b’:’six’, ‘c’:5}, {‘a’:6, ‘b’:’seven’, ‘c’:6}, {‘a’:7, ‘b’:’eight’, ‘c’:7}, {‘a’:8, ‘b’:’nine’, ‘c’:8}, {‘a’:9, ‘b’:’ten’, ‘c’:9}]
2 [{‘a’:10, ‘b’:’eleven’, ‘c’:10}]
我尝试了什么:
Series_dataframe.groupby(np.arange(Series_dataframe.shape[0]) // partitions)
答案 0 :(得分:1)
使用
In [3752]: s.groupby(s.index // 5).apply(list)
Out[3752]:
0 [{u'a': 0, u'c': 0, u'b': u'one'}, {u'a': 1, u...
1 [{u'a': 5, u'c': 5, u'b': u'six'}, {u'a': 6, u...
2 [{u'a': 10, u'c': 10, u'b': u'eleven'}]
Name: s, dtype: object
详细
In [3753]: s
Out[3753]:
0 {u'a': 0, u'c': 0, u'b': u'one'}
1 {u'a': 1, u'c': 1, u'b': u'two'}
2 {u'a': 2, u'c': 2, u'b': u'three'}
3 {u'a': 3, u'c': 3, u'b': u'four'}
4 {u'a': 4, u'c': 4, u'b': u'five'}
5 {u'a': 5, u'c': 5, u'b': u'six'}
6 {u'a': 6, u'c': 6, u'b': u'seven'}
7 {u'a': 7, u'c': 7, u'b': u'eight'}
8 {u'a': 8, u'c': 8, u'b': u'nine'}
9 {u'a': 9, u'c': 9, u'b': u'ten'}
10 {u'a': 10, u'c': 10, u'b': u'eleven'}
Name: s, dtype: object
In [3754]: type(s)
Out[3754]: pandas.core.series.Series