I have a pandas DataFrame composed of a list of objects and then 4 lists of 12 values for each object. It has the general form:
I would like to transpose the dataframe and have hierarchical indices ('Name', 'names of 4 lists'). The general form of this would look like
I have tried the following, with rows_list being my source data:
import pandas as pd
test_table = pd.DataFrame(rows_list, columns=("name", "frac_0", "frac_1","frac_2", "frac_3"))
name = pd.Series(test_table['name'])
del test_table['name']
test_table = test_table.T
test_table = test_table.sort_index([subjectname])
This gives me a TypeError that states
"unhashable type: 'list'".
A simple test_table.T
operation also doesn't give me what I need, as I need columns to correspond to items in the (List1, List2, etc) lists, and the rows to be indexed by name and then List1, List2. I've gone back and forth with adding new columns, or trying to build a brand new DataFrame from multiple series, but nothing seems to work.
Thanks for your help!