Guest User

Untitled

a guest
Jan 22nd, 2019
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1. import csv
  2. import re
  3. #import time
  4.  
  5. with open('resDataset.csv', 'r') as csv_f:
  6. csv_r = csv.reader(csv_f)
  7.  
  8. p1 = re.compile(r'(.*?)Singapore [0-9]{6,6}')
  9. p2 = re.compile(r'(·){2,2}.+')
  10.  
  11. next(csv_r)
  12.  
  13. with open('editedR.csv', 'w', newline='') as csv_f2:
  14. writer = csv.writer(csv_f2)
  15. writer.writerow(['ResName','Rating','Address','GoodFor','Time','Price'])
  16.  
  17. for line in csv_r:
  18. m1 = p1.match(line[2])
  19. n_addr = m1.group()
  20. print(n_addr)
  21.  
  22. m2 = p2.match(line[5])
  23. n_price = m2.group()
  24. print(n_price)
  25.  
  26. writer.writerow([line[0], line[1], n_addr, line[3], line[4], n_price])
  27.  
  28.  
  29. csv_f2.close()
  30. csv_f.close()
Add Comment
Please, Sign In to add comment