Skip to main content

A Python package for cleaning and analyzing Chinese phone numbers.

Project description

Chinese Phone Number Parser

A Python package for cleaning, parsing, and analyzing Chinese phone numbers in various formats.

Features

  • Clean and normalize phone numbers from various formats
  • Extract area codes and map them to corresponding cities
  • Detect different phone number formats (mobile, landline, international, etc.)
  • Handle multiple phone numbers in a single string
  • Support for extensions and special number formats
  • Comprehensive analysis of phone number patterns

Installation

pip install chinese-phone-parser

Quick Start

from chinese_phone_parser import PhoneParser

# Parse a single phone number
parser = PhoneParser()
result = parser.parse("+86-010-12345678")
print(result)
# Output: {
#     'original': '+86-010-12345678',
#     'normalized': '+8601012345678',
#     'type': 'landline',
#     'area_code': '010',
#     'city': 'Beijing'
# }

# Analyze a dataset with phone numbers
import pandas as pd
from chinese_phone_parser.utils.helpers import analyze_phone_dataset, get_phone_stats, plot_phone_formats

# Load your data
df = pd.read_csv('your_data.csv')

# Analyze the dataset
analyzed_df = analyze_phone_dataset(df, phone_column='phone')

# Get comprehensive statistics
stats = get_phone_stats(df, phone_column='phone')

# Create visualizations
fig = plot_phone_formats(df, phone_column='phone')
fig.show()

Supported Phone Number Formats

1. Mobile Numbers (11 digits)

  • Standard: 13812345678
  • International: +86 138 1234 5678
  • With prefix: 0086-13812345678

2. Landline Numbers

  • Local: 010-12345678
  • With area code: 0755-87654321
  • International: +86 10 1234 5678

3. Toll-Free Numbers (10 digits)

  • 400 numbers: 400-123-4567
  • 800 numbers: 800-123-4567

4. Special Formats

  • With extensions:
    • 010-12345678-123
    • 0755-87654321 转 456
    • 010-12345678 ext 789
    • 010-12345678 分机 321
  • Multiple numbers:
    • 010-12345678 / 13812345678
    • 0755-87654321, 400-123-4567
  • Concatenated numbers:
    • 0101234567813812345678
  • Missing area codes:
    • 12345678
    • -12345678
  • Service numbers:
    • 110 (Police)
    • 12345 (Government hotline)

Advanced Features

Pattern Analysis

from chinese_phone_parser.utils.helpers import analyze_phone_patterns

patterns = analyze_phone_patterns(phone_numbers)
print(patterns)
# Output includes:
# - Digit count distribution
# - Extension presence
# - Multiple number detection
# - International format detection
# - Area code analysis
# - Mobile/landline classification

Visualization

from chinese_phone_parser.utils.helpers import plot_area_code_map

# Create a visualization of area code distribution
fig = plot_area_code_map(df, phone_column='phone', top_n=10)
fig.show()

Documentation

For detailed usage and API documentation, please refer to the documentation.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

chinese_phone_parser-0.1.2.tar.gz (16.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

chinese_phone_parser-0.1.2-py3-none-any.whl (18.7 kB view details)

Uploaded Python 3

File details

Details for the file chinese_phone_parser-0.1.2.tar.gz.

File metadata

  • Download URL: chinese_phone_parser-0.1.2.tar.gz
  • Upload date:
  • Size: 16.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.8

File hashes

Hashes for chinese_phone_parser-0.1.2.tar.gz
Algorithm Hash digest
SHA256 bc46d72b78de575cc6780903e6264573b65823ce865a33d54abdbebfc95ba659
MD5 7fa4cc8d3ea372397da529d4509b2319
BLAKE2b-256 61921669a54b9555dcd47a05b1eaf9a93c2ebe3f3d7e33c5c278c2f808ccd2fc

See more details on using hashes here.

File details

Details for the file chinese_phone_parser-0.1.2-py3-none-any.whl.

File metadata

File hashes

Hashes for chinese_phone_parser-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 5c9c5d1ac528ba5cf0b0add0c35d6374ecdc4189f8ac6feac7320e82380b4677
MD5 f7d544a688752a34b0c780cef1ee516d
BLAKE2b-256 da9d1550b68128fe87285c364e3c35b042f5dbeb4954ae0ce4232af930393ab9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page