Question

In: Computer Science

I have a dictionary of phone numbers in a .csv file. There are multiple formats xxx-xxx-xxxx,...

I have a dictionary of phone numbers in a .csv file. There are multiple formats xxx-xxx-xxxx, xxxxxxxxxx, and (xxx) xxx-xxxx. I want to clean them up into one standard format in python.

Solutions

Expert Solution

numbers.csv

97834561234,(976) 456-9785,978-976-3421,9875612334,765-897-3241,(965) 432-6532

#source code:

data=open("numbers.csv","r")
numbers=data.read().split(",")
data.close()
new_number=[]
for i in range(len(numbers)):
   num=""
   for j in range(len(numbers[i])):
       if(numbers[i][j].isdigit()):
           num=num+numbers[i][j]
   new_number.append(num)
print(new_number)
f=open("new_numbers.csv","a+")
f.write(",".join(new_number))
f.close()
  

#output:

#if you have any doubt comment below..if you like give thumbs up....


Related Solutions

Write the correct regular expression pattern for a phone number field with the format XXX-XXX-XXXX
Write the correct regular expression pattern for a phone number field with the format XXX-XXX-XXXX
Create a program that creates and prints a random phone number using the following format: XXX-XXX-XXXX....
Create a program that creates and prints a random phone number using the following format: XXX-XXX-XXXX. Make sure your output include the dashes. Do not let the first three digits contain an 8 or 9 (HINT: do not be more restrictive than that) and make sure that the second set of three digits is not greater than 773. Helpful Hint: Think though the easiest way to construct the phone number. Each digit does do not have to be determined separately....
How would I create a nested dictionary given a csv file in Python? Say I want...
How would I create a nested dictionary given a csv file in Python? Say I want to make a dictionary that read {'country':{'China':'Fit', 'China':'Overweight', 'USA': 'Overweight', 'USA': 'Fit', 'England':'Fit'...}, 'category':{'Asian':'Fit', 'Caucasian': 'Overweight', 'Caucasian':'Overweight', 'Asian': 'Fit', 'Middle Eastern': 'Fit'...}} given a file that had country category Weight China Asian Fit China Caucasian Overweight USA Caucasian Overweight USA Asian Fit England Middle Eastern Fit... ... And so on in the file.
Write a Java program to read in the 10 numbers in the example file Book1.csv provided...
Write a Java program to read in the 10 numbers in the example file Book1.csv provided above. The program should sum all the numbers, find the lowest number, find the highest number, and computer the average. Upon completion of the processing, the program should write a new text file named stats.txt with the information found in the following format where xxx represents a number calculated above. The sum of the numbers is: xxx The lowest number is: xxx The highest...
I have a CSV file with 6 column Issue id action id Issue category Issue date...
I have a CSV file with 6 column Issue id action id Issue category Issue date Issue Closed Date Issue Type Please write a code in Python that counts the number of issues in each category and the earliest and latest issue date for each category. Example of csv Issue id action id Issue category Issue date Issue Closed Date Issue Type 23 1 Noise Complaint 7/19/2020 7/22/2020 Client Complaint 24 1 Cleanliness Complaint 7/19/2020 7/23/2020 Sanitation 25 2 Site...
I am trying to create a program that reads from a csv file and finds the...
I am trying to create a program that reads from a csv file and finds the sum of total volume in liters of liquor sold from the csv file by county and print that list out by county in descending order. Currently my program runs and gives me the right answers but it is not in descending order. I tried this:     for county, volume in sorted(sums_by_volume.items(), key=lambda x: x[1], reverse=True):         index +=1         print("{}. {} {:.2f}".format(county, sums_by_volume[county]))      When I run...
Suppose you are given a file containing a list of names and phone numbers in the...
Suppose you are given a file containing a list of names and phone numbers in the form "First_Last_Phone." In C, Write a program to extract the phone numbers and store them in the output file. Example input/output: Enter the file name: input_names.txt Output file name: phone_input_names.txt 1) Name your program phone_numbers.c 2) The output file name should be the same name but an added phone_ at the beginning. Assume the input file name is no more than 100 characters. Assume...
Suppose you are given a file containing a list of names and phone numbers in the...
Suppose you are given a file containing a list of names and phone numbers in the form "First_Last_Phone." Write a program in C to extract the phone numbers and store them in the output file. Example input/output: Enter the file name: input_names.txt Output file name: phone_input_names.txt 1) Name your program phone_numbers.c 2) The output file name should be the same name but an added phone_ at the beginning. Assume the input file name is no more than 100 characters. Assume...
Suppose you are given a file containing a list of names and phone numbers in the...
Suppose you are given a file containing a list of names and phone numbers in the form "First_Last_Phone." Write a program to extract the phone numbers and store them in the output file. Example input/output: Enter the file name: input_names.txt Output file name: phone_input_names.txt 1) Name your program phone_numbers.c 2) The output file name should be the same name but an added phone_ at the beginning. Assume the input file name is no more than 100 characters. Assume the length...
Suppose you are given a file containing a list of names and phone numbers in the...
Suppose you are given a file containing a list of names and phone numbers in the form "First_Last_Phone." Write a program in C language to extract the phone numbers and store them in the output file. Example input/output: Enter the file name: input_names.txt Output file name: phone_input_names.txt 1) Name your program phone_numbers.c 2) The output file name should be the same name but an added phone_ at the beginning. Assume the input file name is no more than 100 characters....
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT