Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #64467
| From | Ben Finney <ben+python@benfinney.id.au> |
|---|---|
| Subject | Re: Separate Address number and name |
| Date | 2014-01-22 11:08 +1100 |
| References | <9fe1b47b-65ce-4063-9188-07b81cdba49f@googlegroups.com> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.5826.1390349308.18130.python-list@python.org> (permalink) |
Shane Konings <shane.konings@gmail.com> writes:
> I have the following sample from a data set and I am looking to split
> the address number and name into separate headings as seen below.
>
> FarmID Address
> 1 1067 Niagara Stone
> 2 4260 Mountainview
> 3 25 Hunter
> 4 1091 Hutchinson
> 5 5172 Green Lane
> 6 500 Glenridge
> 7 471 Foss
> 8 758 Niagara Stone
> 9 3836 Main
> 10 1025 York
If it is *always* the case that you just want to split the string on the
first space (' ', U+0020) character, then this will do the job:
>>> street_address = "1067 Niagara Stone"
>>> (street_number, street_name) = street_address.split(' ', 1)
>>> street_number
'1067'
>>> street_name
'Niagara Stone'
But that's a very dubious assumption. Are you sure your data contains no
examples like:
PO Box 27
Unit 6, 52 Watford Avenue
Lot D property 107 Sandusky Road
etc.? What is your policy for dealing with data which isn't structured
as you assume?
--
\ “All my life I've had one dream: to achieve my many goals.” |
`\ —Homer, _The Simpsons_ |
_o__) |
Ben Finney
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Separate Address number and name Shane Konings <shane.konings@gmail.com> - 2014-01-21 15:49 -0800
Re: Separate Address number and name Anders Wegge Keller <wegge@wegge.dk> - 2014-01-22 00:55 +0100
Re: Separate Address number and name Shane Konings <shane.konings@gmail.com> - 2014-01-21 16:01 -0800
Re: Separate Address number and name Shane Konings <shane.konings@gmail.com> - 2014-01-21 16:06 -0800
Re: Separate Address number and name Anders Wegge Keller <wegge@wegge.dk> - 2014-01-22 02:04 +0100
Re: Separate Address number and name Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-01-22 10:08 +0000
Re: Separate Address number and name Denis McMahon <denismfmcmahon@gmail.com> - 2014-01-22 17:35 +0000
Re: Separate Address number and name Denis McMahon <denismfmcmahon@gmail.com> - 2014-01-23 18:11 +0000
Re: Separate Address number and name Asaf Las <roegltd@gmail.com> - 2014-01-21 16:08 -0800
Re: Separate Address number and name Ben Finney <ben+python@benfinney.id.au> - 2014-01-22 11:08 +1100
Re: Separate Address number and name John Gordon <gordon@panix.com> - 2014-01-22 02:46 +0000
Re: Separate Address number and name Tim Chase <python.list@tim.thechases.com> - 2014-01-21 21:03 -0600
Re: Separate Address number and name Denis McMahon <denismfmcmahon@gmail.com> - 2014-01-22 15:40 +0000
csiph-web