Adi
Adi

Reputation: 141

Pandas DF MultiIndex Selection

I have a Pandas MultiIndex DataFrame containing experimental results.(Note that it is a dataframe within a dictionary) The DF head can be seen below: DF head

and the tail (it is a long data set): df tail

The DataFrame index: DataFrame Index This DataFrame shows two experiments (calibration_type) : sensitivity and selectivity

I can select a 'calibration_type' using x['raw_data_calibration].xs('selectivity').

How do I:

  1. Drop the calibration_num column (the 0 or 1 refers to the calibration_type as far as I am aware, all calibration_type=sensitivity entries have a calibration_num=1
  2. As can be seen in the following image. The electrode_num refers to 1 of 8 different electrodes in a sensor chip. I would like to group these and transpose them into column headers. So the output DataFrame would have the following columns: electrode_1....electrode_8, raw_time,raw_currentelectrode num

Upvotes: 0

Views: 56

Answers (1)

Phik
Phik

Reputation: 434

Drop the calibration_num column (the 0 or 1 refers to the calibration_type as far as I am aware, all calibration_type=sensitivity entries have a calibration_num=1

x.reset_index(level=1, drop=True)

As can be seen in the following image. The electrode_num refers to 1 of 8 different electrodes in a sensor chip. I would like to group these and transpose them into column headers. So the output DataFrame would have the following columns: electrode_1....electrode_8, raw_time,raw_current

x.unstack(level=-1) With that you will get a MultiIndex column-wise with first level electrode_1...electrode_8 as first level and raw_time..boundary as second level

(Chain the two functions for combining both effects)

Upvotes: 1

Related Questions