Python Forum
pandas dataframe.replace regex
Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
pandas dataframe.replace regex
#1
Dear Pandas Experts,
I am trying to replace occurences like "United Kingdom of Great Britain and Ireland" or "United Kingdom of Great Britain & Ireland"
with just "United Kingdom". So I thought I use a regex to look for strings that contain "United Kingdom".
However, my two attempts below do not work:

    dftwo['Country'].replace(r'^United Kingdom of Great Britain','United Kingdom',inplace=True, regex=True)

    dftwo['Country'].replace('/United Kingdom/','United Kingdom',inplace=True, regex=True)
I would really appreciate any help!
Reply


Messages In This Thread
pandas dataframe.replace regex - by metalray - Feb-24-2017, 09:36 AM
RE: pandas dataframe.replace regex - by zivoni - Feb-24-2017, 10:37 AM
RE: pandas dataframe.replace regex - by metalray - Feb-24-2017, 12:45 PM
RE: pandas dataframe.replace regex - by zivoni - Feb-24-2017, 12:58 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Pandas dataframe indexing pythonNovice 1 1,029 Jun-16-2022, 04:43 PM
Last Post: jefsummers
  How can I convert specific rows from excel to pandas dataframe? mcva 1 1,832 Apr-20-2020, 09:14 AM
Last Post: pyzyx3qwerty
  Histogram using pandas dataframe not showing proper output ift38375 1 2,238 Jul-04-2019, 10:43 PM
Last Post: scidam
  Pandas| iterrows | csv.replace BeerLover 1 4,638 May-19-2017, 05:54 PM
Last Post: buran
  pandas dataframe next rows value metalray 2 10,187 Mar-06-2017, 11:31 AM
Last Post: metalray
  pandas dataframe group by count index metalray 5 10,329 Mar-01-2017, 09:14 AM
Last Post: metalray
  pandas dataframe substracting columns: key error metalray 2 7,097 Feb-24-2017, 07:59 AM
Last Post: metalray

Forum Jump:

User Panel Messages

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