【发布时间】:2018-09-01 10:28:48
【问题描述】:
在分组(按id)数据框df中
id, last_name, first_name
sdfg, Muller, Peter
fgjh, Smith, Rob
fgjh, Smith, Robert
hjsa, Jackson, Michael
我想在开头添加另一个索引person 作为一个正在进行的数字,以便我们得到
person, id, last_name, first_name
0, sdfg, Muller, Peter
1, fgjh, Smith, Rob
1, fgjh, Smith, Robert
2, hjsa, Jackson, Michael
我尝试使用reset_index(...),但无论分组如何,这都会设置一个持续的数字。
有可能吗?
【问题讨论】:
标签: pandas indexing group-by multi-index