Remove rows with repeated index in multiindex dataframe

Viewed 36

I have the following dataframe with a double index. How could I delete those rows where the first index is equal to the second index?

First_index             Second_index          Column                          

PitchAngle              RotorSpeed         -0.163742
GenSpeed                PitchAngle         -0.163689
GearboxBearingTemp      PitchAngle         -0.063614                                              
GenSpeed                GenSpeed            0.325689
AmbientTemperature      AmbientTemperature  0.569469
WindDirection           WindDirection      -0.152658
1 Answers

Do the following:

Load modules

import io
import pandas as pd

Create the data

df = pd.read_csv(io.StringIO("""
First_index             Second_index          Column                          
PitchAngle              RotorSpeed         -0.163742
GenSpeed                PitchAngle         -0.163689
GearboxBearingTemp      PitchAngle         -0.063614                                              
GenSpeed                GenSpeed            0.325689
AmbientTemperature      AmbientTemperature  0.569469
WindDirection           WindDirection      -0.152658
"""), sep="\s\s+", engine="python")

Do not select the rows where first index is equal to second index

df[~(df.First_index == df.Second_index)]
Related