[Python] Check if Pandas Dataframe row contains a string [duplicate]

Discussão em 'Python' iniciado por Stack, Setembro 24, 2024.

  1. Stack

    Stack Membro Participativo

    Im using pandas to read out an excel file that ive exported from some software I use. I need to select all the rows from the dataframe where the column 'Component' contains the string 'WTG' and the column 'Field' is equal to 'Voltage'. That second part is easy, but I cant get the first one to work. The actual values in the Component column are along the lines of 'BUS-WTG-123'.

    I tried poi_Volts = db[("WTG" in db['Component']) & (db['Field'] == 'Voltage')] and it executes but returns an empty dataframe. If i instead use for L in range(0,len(db)): if ("WTG" in db['Component'][L]) and (db['Field'][L] == 'Voltage'):, it returns the rows I need, but not as a pandas dataframe, and it requires iteration, which id like to avoid.

    here is a sample row from the df: BUS2-WTG-C08 | Voltage | 108.2 | 108.4 | 109.2 | ...

    Continue reading...

Compartilhe esta Página