0

I have the following dataframe:

      import pandas as pd

      dataframe = pd.DataFrame({'ID_Sensor': [1, 1, 1, 2, 2, 3, 3], 
                      'Type': ['Analog', 'Analog', 'Analog', 'Dig', 'Dig', 'Analog', 'Analog'],
                      'Value': [100, 200, 300, 1, 0, 400, 500]})

I would like to keep only the first line of each of the sensor identifiers. I tried to use the head () function, but it only returns the first line:

      dataframe.head(1)

My output:

      ID_Sensor    Type     Value
            1     Analog     100

Desired output:

     ID_Sensor  Type    Value
        1       Analog  100
        2        Dig     1
        3       Analog  400
Jane Borges
  • 552
  • 5
  • 14

1 Answers1

1

Please use groupby and chain .first

dataframe.groupby(['ID_Sensor','Type'])['Value'].first()
wwnde
  • 26,119
  • 6
  • 18
  • 32