So I have a .csv file with names, lat, lon, and phone number; separated by comma. I need to open the file, edit the phone number into a more legible format and then write that back to the file.
There is a nice solution to editing the phone numbers Here
Not really sure of the best way to approach this problem. Any help is greatly appreciated. Thanks.
import csv
def phone_format(n):
return format(int(n[:-1]), ",").replace(",", "-") +n[-1]
with open('sample.csv', 'rU') as csvfile:
spotreader = csv.reader(csvfile)
spotwriter = csv.writer(csvfile)
for row in spotreader:
spotwriter.writerow([0] + phone_format(spotreader[1]))
This does not work. Not really sure how to get what I am looking for.
Sample of my csv file below
Jason Schow,,5016098648
Dena VanGorder,,6074621816
Lindsey McNabb,3066533971,3066505001
Jeff Wozniak,3066531566,3069420647
Victoria Norton,3067692840,3067697062
Benjie Butikofer,3067692107,3067697108
Jessica Duede,,3062813158
Pete Vogeh,3063776261,3069890349
Melissa Kwasney,,3069412583
Type of output to .csv file that I am looking for below:
Jason Schow,,501-609-8648
Dena VanGorder,,607-462-1816
Lindsey McNabb,306-653-3971,306-650-5001
Jeff Wozniak,306-653-1566,306-942-0647
Victoria Norton,306-769-2840,306-769-7062
Benjie Butikofer,306-769-2107,306-769-7108
Jessica Duede,,306-281-3158
Pete Vogeh,306-377-6261,306-989-0349
Melissa Kwasney,,306-941-2583