Separate Address number and name

Denis McMahon denismfmcmahon at gmail.com
Wed Jan 22 10:40:27 EST 2014


On Tue, 21 Jan 2014 15:49:16 -0800, Shane Konings wrote:

> 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
> 
> 
> FarmID	AddressNum    AddressName 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
> 
> I have struggled with this for a while and know there must be a simple
> method to achieve this result.

Unfortunately the vagaries of nntp, my client and the google nntp posting 
host are such that I can't discern the format of your data from your post.

However, if as I think you have a text field that is always:

<1 or more digits><1 or more spaces><the rest>

where you want to capture the initial "1 or more digits" and "the rest" 
as 2 data elements then this should be possible with a simple re:

(\d+)\s+(.*)

If you have numeric id, whitespace, numeric addr bit, whitespace, the 
rest, then you may need something more like:

(\d+)\s+(\d+)\s+(.*)

The assumption is that it's not necessary to hold your hand through the 
whole looping through the input and applying the re to each line, then 
reading the captured bits and using them process.

-- 
Denis McMahon, denismfmcmahon at gmail.com



More information about the Python-list mailing list