小编Sup*_*ugy的帖子

GroupBy结果列表的列表

我有一张excel表,看起来像这样:

Column1 Column2 Column3
0       23      1
1       5       2
1       2       3
1       19      5
2       56      1
2       22      2
3       2       4
3       14      5
4       59      1
5       44      1
5       1       2
5       87      3
Run Code Online (Sandbox Code Playgroud)

我希望提取该数据,将其按第1列分组,然后将其添加到字典中,使其显示如下:

{0: [1],
1: [2,3,5],
2: [1,2],
3: [4,5],
4: [1],
5: [1,2,3]}
Run Code Online (Sandbox Code Playgroud)

到目前为止这是我的代码

excel = pandas.read_excel(r"e:\test_data.xlsx", sheetname='mySheet', parse_cols'A,C')
myTable = excel.groupby("Column1").groups
print myTable
Run Code Online (Sandbox Code Playgroud)

但是,我的输出看起来像这样:

{0: [0L], 1: [1L, 2L, 3L], 2: [4L, 5L], 3: [6L, 7L], 4: [8L], 5: …
Run Code Online (Sandbox Code Playgroud)

python xlrd pandas

20
推荐指数
2
解决办法
1万
查看次数

标签 统计

pandas ×1

python ×1

xlrd ×1