python - Parsing out indeces and values from pandas multi index dataframe -


i have dataframe in similar format this:

+--------+--------+----------+------+------+------+------+ |        |        |          |      | day1 | day2 | day3 | +--------+--------+----------+------+------+------+------+ | id_one | id_two | id_three | date |      |      |      | | 18273  | 50     | 1        | 3    |    9 |   11 |    3 | |        |        |          | 4    |   26 |   27 |   68 | |        |        |          | 5    |   92 |   25 |    4 | |        |        |          | 6    |   60 |   72 |   83 | |        | 60     | 2        | 5    |   69 |   93 |   84 | |        |        |          | 6    |   69 |   30 |   12 | |        |        |          | 7    |   65 |   65 |   59 | |        |        |          | 8    |   57 |   88 |   59 | |        | 70     | 3        | 5    |   22 |   95 |    7 | |        |        |          | 6    |   40 |   24 |   20 | |        |        |          | 7    |   73 |   81 |   57 | |        |        |          | 8    |   43 |    8 |   66 | +--------+--------+----------+------+------+------+------+ 

i trying create tuple contains id_one, id_two , values each grouping contains.

to test this, trying print ids , values this:

for id_two, data in df.head(100).groupby(level='id_two'):     print id_two, data.values.ravel() 

which gives me id_two , data should.

i running problems when try , incorporate id_one. tried this, met error valueerror: need more 2 values unpack

for id_one, id_two, data in df.head(100).groupby(level='id_two'):     print id_one, id_two, data.values.ravel() 

how can print id_one, id_two , data?

you can pass list of columns level parameter:

df.head.groupby(level=['id_one', 'id_two']) 

Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

php - Find a regex to take part of Email -

javascript - Function overwritting -