Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Newbee - substing of column
#3
Thanks for reply Larz. I have a dataframe/table with 10,000 records. One of the fields is called LSOA name. Example as per below:

Crawley 999B
Leicester NBB99
Market Harborough ZZZ1
London 111V

What I want is just the place name, ie the text excluding the 4 character code (and the space) on the right. So the above would be:

Crawley
Leicester
Market Harborough
London

In sql I would use select "substr(['LSOA name'],1,len(['LSOA name'])-5) as LSOA_Area from..."

This means... take the field LSOA Name, take from the 1st character to the last character of the name minus 4 character from the right. So, "London 111V" loses the last 4 characters (and the spcase) and becomes "London".

Thanks

Andrew
Reply


Messages In This Thread
Newbee - substing of column - by andrewjmdata - Feb-17-2018, 02:26 PM
RE: Newbee - substing of column - by Larz60+ - Feb-17-2018, 02:39 PM
RE: Newbee - substing of column - by andrewjmdata - Feb-17-2018, 07:04 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  file handling Newbee question middlecope 2 785 Jan-18-2023, 03:09 PM
Last Post: middlecope
  Newbee Question chas777 4 2,257 Apr-01-2020, 06:52 PM
Last Post: chas777
  Useless Newbee craigpusey 2 69,520 Mar-04-2020, 02:13 PM
Last Post: craigpusey

Forum Jump:

User Panel Messages

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