[Tutor] My problem in simple terms

Edward Kanja edwardkanja254 at gmail.com
Mon Mar 4 06:44:05 EST 2019


Hi there ,
Earlier i had sent an email on how to use re.sub function to eliminate
square brackets. I have simplified the statements. Attached txt file named
unon.Txt has the data im extracting from. The file named code.txt has the
codes I'm using to extract the data.The regular expression works fine but
my output has too many square brackets. How do i do away with them thanks.



Regards,
Kanja Edward.
P.O.BOX 1203-00300,
NAIROBI.
*+254720724793*
www.linkedin.com/in/edward-kanja-bba16a106 <http://linkeldin/>
-------------- next part --------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|Rawzeea NLKPP                         | VE11-Nairobi                            | 20002254-MADIZ                        | 00           | 00               |Regular Scheme B | 15-JAN-2019 To 31-DEC-2019 | No       |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 11113648                             | 18-FEB-2020 | Yes         | 03          |      0000.00 USD  |         0.00 USD  | Leased Commercially                               |           000000.00 KES    | No       |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| R-9-01                               | 00.00%      |0023.28 KES  |000.18 USD   |                   |  1.00000          |  0.00        |  0.00            | No              | 10-JAN-2019 To 31-DEC-2019            |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
                                       | Valid From: 17-Jan-2017                                                         | Warwass Center                                                                            |
                                       | Warwass Center                                                                  | UK-8                                                                                      |
                                       |                                                                                 | UK Avenue                                                                                 |
                                       | Nairobi---Kenya                                                                 |                                                                                           |
                                       |                                                                                 | Nairobi--00100-Kenya                                                                      |
                                       |                                                                                 | 0207690606                                                                                |
                                       |                                                                                 | housert at weekly.com                                                                 |
                                       -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
|Pattly MUNIIZ                         | TX00-Nairobi                            | 20000006-KZAU                         | 00           | 00               |Regular Scheme B | 05-JAN-2010 To 01-JAN-2019 | No       |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 10000007                             | 07-DEC-2019 | No          | 00          |      0000.00 USD  |         0.00 USD  | Leased Commercially                               |           000000.00 KES    | No       |
|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| K-3-10                               | 00.00%      |0000.25 KES  |0000.60 USD  |                   |  1.00000          |  0.00        |  0.00            | No              | 01-JAN-2019 To 01-JAN-2000            |
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
                                       | Valid From: 65-Feb-2010                                                         | Kuthat Skuh                                                                               |
                                       | 98 Runka road                                                                   | 98                                                                                        |
                                       |                                                                                 | Runka Road                                                                                |
                                       | Nairobi---Kenya                                                                 |                                                                                           |
                                       |                                                                                 | Nairobi--00200-Kenya                                                                      |
                                       |                                                                                 |                                                                                           |
                                       |                                                                                 |                                                                                           |
                                       -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
                     
                         
-------------- next part --------------
import pandas as pd
from pandas import DataFrame #creating my dataframes manually.
import re
#import textfile

with open ('unon.txt') as csvfile:
	mydata=pd.read_csv('unon.txt')

	for line in csvfile:
		
		index_no=re.findall(r'(\|\s\d{5,8}\s)',line)
		
		names=re.findall(r'(\|[A-Za-z]\w*\s\w*\s\w*\s\w*\s)',line)
		#Address=re.findall(r'\|\s([A-Z0-9-,/]\w*\s\w*\s)',line)
		
		duty_station=re.findall(r'\|\s[A-Z]*\d{2}\-\w\w\w\w\w\w\w\s',line)

		print((index_no),(names),(duty_station))


More information about the Tutor mailing list