I'm trying to convert DataFrame that looks like this:
i j n
1 1 2 #
2 1 3 #
3 1 5 #
4 2 1 #
5 2 2 #
6 2 4 #
7 3 5 #
8 3 6 #
to a MultiIndex DataFrame like this:
n
1 2 #
3 #
5 #
2 1 #
2 #
4 #
3 5 #
6 #
I don't want to go row by row and inserting into a new DataFrame and I'm sure that there's a quicker way anyway.
Welp,我最初误解了文档,解决方案非常简单: df.set_index(['i', 'j'])
产生预期的效果。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.