I have a dataframe that contains 3 channels of measured data recorded at various depths.
5 5 5 10 10 10
x y z x y z
1 -22.2 0.9 -88.6 -124.8 -76.7 83.2
2 -94.7 -67.9 -162.6 -200.8 -159.0 2.2
3 -128.7 -99.7 -196.4 -248.5 -219.8 -46.8
4 -127.8 -98.4 -195.1 -256.4 -239.1 -55.7
5 -141.0 -110.9 -208.8 -275.2 -265.7 -76.9
6 -142.1 -111.5 -209.6 -280.7 -276.3 -83.3
7 -147.1 -116.0 -214.6 -287.8 -286.0 -91.6
8 -149.2 -117.8 -216.7 -291.5 -290.9 -96.0
The dataframe is multi indexed using a repeating sequence of X, Y and Z (for each of the 3 components) and a floating point depth, as follows:
c = list(itertools.repeat(['x','y', 'z'], n))
col_a = list(itertools.chain(*c))
col_b = natsorted (depths * 3)
df.columns = [cola, colb]
Where n is the number of depths and depths is a user defined list of floats describing the depth of each measurement (5 and 10 in the example table above).
I would like to be able to create subsets of the data (to write to csv or to plot on the screen) from either of the column index levels. Selecting the component (X, Y or Z) isn't an issue.
x1 = df['x']
x1.to_csv(x_out.csv')
However, selecting all columns from a particular depth doesn't work
x1 = df['10']
I have tried various forms .ix and .loc but I think that the problem may lie in the float data type of the "depth" coumns key.
My question is, is there a way to select the subset based upon a column key of floating point values or would I be better of using a different method here?
depthcolumn and only have one each ofx,y, andz. Then you could selectdf[df.depth == 10][5,5,5,5,5,10,10,10,10,10,15,15,15,51,15].