This question may have been answeered, but I can’t seem to find the right keywords to search.
current df:
index | time | value | type | test |
---|---|---|---|---|
0 | 0.00 | 0.112 | A | test1 |
1 | 0.01 | 0.113 | A | test1 |
0 | 0.00 | 0.112 | A | test2 |
1 | 0.01 | 0.113 | A | test2 |
Desired df: (each unique value of test gets its own column)
index | time | test1 | test2 | type |
---|---|---|---|---|
0 | 0.00 | 0.112 | 0.112 | A |
1 | 0.01 | 0.113 | 0.112 | A |
0 | 0.00 | 0.112 | 0.112 | B |
1 | 0.01 | 0.113 | 0.112 | B |
I have tried this code:
df_pvt = df.pivot(index = ['index','type'],columns = 'test', values='value')
but, I get a bunch of NaN values and the row count for df_pvt is the same as df, even though it should be 1/5 of the length for 5 unique test values.