<jupyter_start><jupyter_text>`clean_phone()`: Clean and validate phone numbers  IntroductionThe function `clean_phone()` cleans a column containing phone numbers, and standardizes them in a desired format. The function `validate_phone()` validates either a single phone number or a column of phone numbers, returning True if the value is valid, and False otherwise.Currently, Canadian/US phone numbers having the following format are supported as valid input:* Country code of "1" (optional)* Three-digit area code (optional)* Three-digit central office code* Four-digit station code* Extension number preceded by "", "x", "ext", or "extension" (optional)Various delimiters between the digits are also allowed, such as spaces, hyphens, periods, brackets, and/or forward slashes.Phone numbers can be converted to the following formats via the `output_format` parameter:* North American Numbering Plan (nanp): NPA-NXX-XXXX* E.164 (e164): +1NPANXXXXXX* national: (NPA) NXX-XXXXInvalid parsing is handled with the `errors` parameter:* "coerce" (default), then invalid parsing will be set as NaN* "ignore", then invalid parsing will return the input* "raise", then invalid parsing will raise an exceptionAfter cleaning, a **report** is printed that provides the following information:* How many values were cleaned (the value must be transformed)* How many values could not be parsed* And the data summary: how many values are in the correct format, and how many values are nullThe following sections demonstrate the functionality of `clean_phone()` and `validate_phone()`.   An example dirty dataset<jupyter_code>import pandas as pd
import numpy as np
df = pd.DataFrame({"messy_phone":
                   ["555-234-5678", "(555) 234-5678", "555.234.5678", "555/234/5678",
                    15551234567, "(1) 555-234-5678", "+1 (234) 567-8901 x. 1234", 
                    "2345678901 extension 1234", "2345678", "+66 91 889 8948", 
                    "hello", np.nan, "NULL"]
                  })
df<jupyter_output><empty_output><jupyter_text>1. Default `clean_phone()` By default, the `output_format` parameter is set to "nanp" (NPA-NXX-XXXX) and the `errors` parameter is set to "coerce" (set to NaN when parsing is invalid).<jupyter_code>from dataprep.clean import clean_phone
clean_phone(df, "messy_phone")<jupyter_output>Phone Number Cleaning Report:
	8 values cleaned (61.54%)
	2 values unable to be parsed (15.38%), set to NaN
Result contains 9 (69.23%) values in the correct format and 4 null values (30.77%)<jupyter_text>Note that "555-234-5678" is considered not cleaned in the report since its resulting format is the same as the input. Also, "+66 91 889 8948" is invalid because it is not a Canadian or US phone number.  2. Output formatsThis section demonstrates the supported phone number formats. E.164 (e164)<jupyter_code>clean_phone(df, "messy_phone", output_format="e164")<jupyter_output>Phone Number Cleaning Report:
	8 values cleaned (61.54%)
	2 values unable to be parsed (15.38%), set to NaN
Result contains 9 (69.23%) values in the correct format and 4 null values (30.77%)<jupyter_text>Note that the country code "+1" is not added to "2345678" as this would result in an invalid Canadian or US phone number.  national<jupyter_code>clean_phone(df, "messy_phone", output_format="national")<jupyter_output>Phone Number Cleaning Report:
	8 values cleaned (61.54%)
	2 values unable to be parsed (15.38%), set to NaN
Result contains 9 (69.23%) values in the correct format and 4 null values (30.77%)<jupyter_text>3. `split` parameterThe `split` parameter adds individual columns containing the cleaned phone number values to the given DataFrame.<jupyter_code>clean_phone(df, "messy_phone", split=True)<jupyter_output>Phone Number Cleaning Report:
	9 values cleaned (69.23%)
	2 values unable to be parsed (15.38%), set to NaN
Result contains 9 (69.23%) values in the correct format and 4 null values (30.77%)<jupyter_text>4. `fix_missing` parameterBy default, the `fix_missing` parameter is set to "empty" (leave the missing country code as is). If set to "auto", the country code is set to "1". `split` and `fix_missing`<jupyter_code>clean_phone(df, "messy_phone", split=True, fix_missing="auto")<jupyter_output>Phone Number Cleaning Report:
	9 values cleaned (69.23%)
	2 values unable to be parsed (15.38%), set to NaN
Result contains 9 (69.23%) values in the correct format and 4 null values (30.77%)<jupyter_text>Again, note that the country code is not set to "1" for "2345678" as this would result in an invalid Canadian or US phone number.  5. `inplace` parameterThis deletes the given column from the returned DataFrame. A new column containing cleaned phone numbers is added with a title in the format `"{original title}_clean"`.<jupyter_code>clean_phone(df, "messy_phone", inplace=True)<jupyter_output>Phone Number Cleaning Report:
	8 values cleaned (61.54%)
	2 values unable to be parsed (15.38%), set to NaN
Result contains 9 (69.23%) values in the correct format and 4 null values (30.77%)<jupyter_text>`inplace` and `split`<jupyter_code>clean_phone(df, "messy_phone", split=True, inplace=True)<jupyter_output>Phone Number Cleaning Report:
	9 values cleaned (69.23%)
	2 values unable to be parsed (15.38%), set to NaN
Result contains 9 (69.23%) values in the correct format and 4 null values (30.77%)<jupyter_text>`inplace`, `split` and `fix_missing`<jupyter_code>clean_phone(df, "messy_phone", split=True, inplace=True, fix_missing="auto")<jupyter_output>Phone Number Cleaning Report:
	9 values cleaned (69.23%)
	2 values unable to be parsed (15.38%), set to NaN
Result contains 9 (69.23%) values in the correct format and 4 null values (30.77%)<jupyter_text>6. `validate_phone()` `validate_phone()` returns True when the input is a valid phone number. Otherwise it returns False.Valid types are the same as `clean_phone()`.<jupyter_code>from dataprep.clean import validate_phone
print(validate_phone(1234))
print(validate_phone(2346789))
print(validate_phone("1 800 234 6789"))
print(validate_phone("+44 7700 900077"))
print(validate_phone("555-234-6789 ext 32"))
df = pd.DataFrame({"messy_phone":
                   ["555-234-5678", "(555) 234-5678", "555.234.5678", "555/234/5678",
                    15551234567, "(1) 555-234-5678", "+1 (234) 567-8901 x. 1234", 
                    "2345678901 extension 1234", "2345678", "+66 91 889 8948", 
                    "hello", np.nan, "NULL"]
                  })
df["valid"] = validate_phone(df["messy_phone"])
df<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10406130268199233, 'fraction_numerical': 0.0743295019157088, 'mean_word_length': 4.852914798206278, 'pattern_counts': {'":': 2, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '10', 'dir': 'jupyter-structured-clean-dedup', 'id': '657267', 'license': 'MIT', 'n_tokens_mistral': 2281, 'n_tokens_neox': 1917, 'n_words': 789, 'path': 'docs/source/user_guide/clean/clean_phone.ipynb', 'repo_name': 'juandavidospina/dataprep', 'size': '6525'}