3

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
2
  • Do you really mean remove the row or do you mean adapt the multi-index where first index is equal to second? Commented Dec 11, 2020 at 11:10
  • I mean removing the row, so I'm only interesed in getting those rows where first and second index are different Commented Dec 11, 2020 at 11:12

1 Answer 1

1

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)]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.