New member
- Joined
- Feb 7, 2023
- Messages
- 27
- Thread Author
- #1
I want to extract rows from a pandas data frame based on the values of a column using regex in contains() method.
I am using the following code line to extract rows from a data frame if the 'COMPTYPE' column has any string value mentioned in contains() method
It works fine however it's not selecting those rows which have MccB or Vcb or Contactor or acb etc. values in the 'COMPTYPE' column. How to use this command so it will take rows irrespective of the case of the string values.
Input:
Expected output is this,
However, I'm getting following output,
How to do it? Please help!
I am using the following code line to extract rows from a data frame if the 'COMPTYPE' column has any string value mentioned in contains() method
Code:
df = df[df['COMPTYPE'].astype(str).str.contains('MCCB|ACB|VCB|CONTACTOR', regex=True)]
It works fine however it's not selecting those rows which have MccB or Vcb or Contactor or acb etc. values in the 'COMPTYPE' column. How to use this command so it will take rows irrespective of the case of the string values.
Input:
BOARDIBNO | SUBCOMP_IBNO | COMPTYPE |
---|---|---|
1044444001 | 9044444001 | ACB |
1044444001 | 9044444002 | Relay |
1044444001 | 9044444003 | Meters |
1044444001 | 9044444004 | MCCB/MPCB |
1044444001 | 9044444005 | vcb |
1044444001 | 9044444006 | MCCB/MPCB |
1044444001 | 9044444007 | acb |
1044444001 | 9044444008 | mccb |
1044444001 | 9044444009 | MCCB/MPCB |
1044444001 | 9044444010 | Power Contactor |
1044444001 | 9044444011 | Power Contactor |
1044444001 | 9044444012 | Control Contactor |
1044444001 | 9044444013 | VCB |
BOARDIBNO | SUBCOMP_IBNO | COMPTYPE |
---|---|---|
1044444001 | 9044444001 | ACB |
1044444001 | 9044444004 | MCCB/MPCB |
1044444001 | 9044444005 | vcb |
1044444001 | 9044444006 | MCCB/MPCB |
1044444001 | 9044444007 | acb |
1044444001 | 9044444008 | mccb |
1044444001 | 9044444009 | MCCB/MPCB |
1044444001 | 9044444010 | Power Contactor |
1044444001 | 9044444011 | Power Contactor |
1044444001 | 9044444012 | Control Contactor |
1044444001 | 9044444013 | VCB |
BOARDIBNO | SUBCOMP_IBNO | COMPTYPE |
---|---|---|
1044444001 | 9044444001 | ACB |
1044444001 | 9044444004 | MCCB/MPCB |
1044444001 | 9044444005 | MCCB/MPCB |
1044444001 | 9044444006 | MCCB/MPCB |
1044444001 | 9044444010 | VCB |