Python Forum
PowerBI: Using Python Regex to look for values in column
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
PowerBI: Using Python Regex to look for values in column
#1
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?
Yoriz write Oct-14-2022, 10:31 AM:
Please post all code, output and errors (in their entirety) between their respective tags. Refer to BBCode help topic on how to post. Use the "Preview Post" button to make sure the code is presented as you expect before hitting the "Post Reply/Thread" button.
Reply
#2
(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]"
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Get an average of the unique values of a column with group by condition and assign it klllmmm 0 220 Feb-17-2024, 05:53 PM
Last Post: klllmmm
  Converting column of values into muliple columns of counts highland44 0 205 Feb-01-2024, 12:48 AM
Last Post: highland44
  Python Regex quest 2 2,229 Sep-22-2022, 03:15 AM
Last Post: quest
  How to combine multiple column values into 1? cubangt 15 2,626 Aug-11-2022, 08:25 PM
Last Post: cubangt
  Reshaping a single column in to multiple column using Python sahar 7 1,968 Jun-20-2022, 12:35 PM
Last Post: deanhystad
  Creating a numpy array from specific values of a spreadsheet column JulianZ 0 1,076 Apr-19-2022, 07:36 AM
Last Post: JulianZ
  How to split file by same values from column from imported CSV file? Paqqno 5 2,705 Mar-24-2022, 05:25 PM
Last Post: Paqqno
  Float Slider - Affecting Values in Column 'Pandas' planckepoch86 0 1,370 Jan-22-2022, 02:18 PM
Last Post: planckepoch86
  Pandas (Python) in powerBI loop abderrazak_rouchad77 0 1,257 Nov-08-2021, 12:54 AM
Last Post: abderrazak_rouchad77
  python regex: get rid of double dot wardancer84 4 2,309 Sep-09-2021, 03:03 PM
Last Post: wardancer84

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020