Assuming your data source is in a csv file,
from pandas.io.parsers import read_csv
df = read_csv("radar_data.csv")
df # shows what is in df
loc speed time
0 A 63 0
1 B 61 0
2 C 63 0
3 D 65 0
4 A 73 5
5 B 73 5
6 C 75 5
7 D 75 5
8 A 67 0
9 B 68 0
10 C 68 0
11 D 70 0
Note that I did not set loc
as the index yet so it uses an autoincrement integer index.
panel = df.set_index(['loc', 'time']).sortlevel(0).to_panel()
However, if your data frame is already using loc
as the index, we will need to append the time
column into it so that we have a loc-time hierarchal index. This can be done using the new append
option in the set_index
method. Like this:-
panel = df.set_index(['time'], append=True).sortlevel(0).to_panel()
In either case, we should arrive at this scenario:-
panel # shows what panel is
<class 'pandas.core.panel.Panel'>
Dimensions: 1 (items) x 4 (major) x 2 (minor)
Items: speed to speed
Major axis: A to D
Minor axis: 0 to 5
panel["speed"] # <--- This is what you are looking for.
time 0 5
loc
A 63 67
B 73 61
C 68 73
D 63 68
Hope this helps.