I have a pandas data frame which is a result of pivoting. It has multiple indices. I want to get a "normal" data frame out of this pivoted df...so that I can do some normal operations on the new df.
Here is an example: My pivoted data frame looks like this:
feature_value
feature_type f1 f2 f3 f4 f5
time name
2016-05-10 Clay 0 1 30 4 40
2016-05-10 John 0 4 10 4 66
2016-05-10 Mary 0 1 40 4 46
2016-05-10 Boby 2 0 30 4 59
2016-05-10 Lucy 5 8 20 4 41
The following is what I want as a new df:
time name f1 f2 f3 f4 f5
2016-05-10 Clay 0 1 30 4 40
2016-05-10 John 0 4 10 4 66
2016-05-10 Mary 0 1 40 4 46
2016-05-10 Boby 2 0 30 4 59
2016-05-10 Lucy 5 8 20 4 41
How can I do this?
The pivoted_df.to_dict() looks like this:
{('feature_value', 'f1'): {(Timestamp('2016-05-10'), 'Clay'): 0, (Timestamp('2016-05-10'), 'John'): 0, (Timestamp('2016-05-10'), 'Mary'): 0, (Timestamp('2016-05-10'), 'Boby'): 2, (Timestamp('2016-05-10'), 'Lucy'): 5}, ('feature_value', 'f2'): {(Timestamp('2016-05-10'), 'Clay'): 1, (Timestamp('2016-05-10'), 'John'): 4, (Timestamp('2016-05-10'), 'Mary'): 1, (Timestamp('2016-05-10'), 'Boby'): 0, (Timestamp('2016-05-10'), 'Lucy'): 8}, ('feature_value', 'f3'): {(Timestamp('2016-05-10'), 'Clay'): 30, (Timestamp('2016-05-10'), 'John'): 10, (Timestamp('2016-05-10'), 'Mary'): 40, (Timestamp('2016-05-10'), 'Boby'): 30, (Timestamp('2016-05-10'), 'Lucy'): 20}, ('feature_value', 'f4'): {(Timestamp('2016-05-10'), 'Clay'): 4, (Timestamp('2016-05-10'), 'John'): 4, (Timestamp('2016-05-10'), 'Mary'): 4, (Timestamp('2016-05-10'), 'Boby'): 4, (Timestamp('2016-05-10'), 'Lucy'): 4}, ('feature_value', 'f5'): {(Timestamp('2016-05-10'), 'Clay'): 40, (Timestamp('2016-05-10'), 'John'): 66, (Timestamp('2016-05-10'), 'Mary'): 46, (Timestamp('2016-05-10'), 'Boby'): 59, (Timestamp('2016-05-10'), 'Lucy'): 41}}