0

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
Adi
  • 131
  • 2
  • 3
  • 9
  • 1
    paste real data here would be better. See https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples – Tai Jan 16 '18 at 21:39

1 Answers1

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

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)

Phik
  • 414
  • 3
  • 15