PowerBI: Using Python Regex to look for values in column - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: General Coding Help (https://python-forum.io/forum-8.html) +--- Thread: PowerBI: Using Python Regex to look for values in column (/thread-38447.html) |
PowerBI: Using Python Regex to look for values in column - MarcusR44 - Oct-14-2022 I'm trying to add a column called ofInterest to select UK postcodes that match RG, OX & SA, the column would contain a 1 if the match is found, or 0 if not found. My code is: import pandas as pd import re dataset["ofInterest"] = dataset["RegAddress.PostCode"].re.search("[SRO][AGX][0-9]")I'm sure I've got this all wrong because I have very little experience of Python (I know REGEX quite well) - can anybody help me? RE: PowerBI: Using Python Regex to look for values in column - ibreeden - Oct-14-2022 (Oct-14-2022, 10:24 AM)MarcusR44 Wrote: re.search("[SRO][AGX][0-9]"I hope that you are aware also SG, SX, RA, RX, OA and OG will be selected. I think you would rather use: re.search(r"(RG|OX|SA)[0-9]" |