我们可以创建DF的字典:
In [166]: dfs = {k:v for k,v in df.groupby('id')}In [168]: dfs.keys()Out[168]: dict_keys(['W', 'Y', 'Z'])In [169]: dfs['W']Out[169]: A B C D id0 -0.373021 -0.555218 0.022980 -0.512323 W1 -1.599466 0.637292 0.045059 -0.334030 W2 0.100659 0.557068 0.142226 -0.186214 WIn [170]: dfs['Y']Out[170]: A B C D id5 0.540107 -0.739077 0.992408 2.010203 Y6 -0.201376 -0.913222 -0.173284 1.837442 Y7 -1.367659 0.915360 0.072720 -0.886071 YIn [171]: dfs['Z']Out[171]: A B C D id3 -0.329087 0.842431 0.839319 -0.597823 Z4 -0.594375 -0.950486 1.125584 0.116599 Z8 0.366667 -0.978279 -1.449893 0.192451 Z9 -0.007439 -0.084612 0.010192 -0.417602 Z
更新: 重置索引:
In [177]: {k:v.reset_index(drop=True) for k,v in df.groupby('id')}Out[177]:{'W':A B C D id 0 -0.373021 -0.555218 0.022980 -0.512323 W 1 -1.599466 0.637292 0.045059 -0.334030 W 2 0.100659 0.557068 0.142226 -0.186214 W, 'Y':A B C D id 0 0.540107 -0.739077 0.992408 2.010203 Y 1 -0.201376 -0.913222 -0.173284 1.837442 Y 2 -1.367659 0.915360 0.072720 -0.886071 Y, 'Z':A B C D id 0 -0.329087 0.842431 0.839319 -0.597823 Z 1 -0.594375 -0.950486 1.125584 0.116599 Z 2 0.366667 -0.978279 -1.449893 0.192451 Z 3 -0.007439 -0.084612 0.010192 -0.417602 Z}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)