简体   繁体   English

如何使用 python 将电话号码导出到 Excel 文件中?

[英]How do you export phone numbers into Excel file using python?

#也许我建议可以使用 pandas 和 open_cv 库 Import pandas Import open_cv

For extraction of phone number from your dataframe.用于从您的数据框中提取电话号码。 go with some regular expression according to your scenario.根据您的情况使用一些正则表达式。

import pandas as pd
import re as re

def find_phone_number(text):
    ph_no = re.findall(r"\b\d{10}\b",text)
    return "".join(ph_no)

df = pd.DataFrame({
    'id': ['c0001','c0002','c0003', 'c0003', 'c0004'],
    'text': ['Company1-Phone no. 4695168357','Company2-Phone no. 8088729013','Company3-Phone no. 6204658086', 'Company4-Phone no. 5159530096', 'Company5-Phone no. 9037952371']
    })

df['Phone number']=df['text'].apply(lambda x: find_phone_number(x))

The orginal dataframe is,原始数据框是,

     ids                           text
0  c0001  Company1-Phone no. 4695168357
1  c0002  Company2-Phone no. 8088729013
2  c0003  Company3-Phone no. 6204658086
3  c0003  Company4-Phone no. 5159530096
4  c0004  Company5-Phone no. 9037952371

the corresponding output is,相应的输出是,

     ids                           text Phone number
0  c0001  Company1-Phone no. 4695168357   4695168357
1  c0002  Company2-Phone no. 8088729013   8088729013
2  c0003  Company3-Phone no. 6204658086   6204658086
3  c0003  Company4-Phone no. 5159530096   5159530096
4  c0004  Company5-Phone no. 9037952371   9037952371

Make sure while asking question in stackoverflow, drop your duplicate data and your code execution and also with your expected result or problem you were facing.确保在 stackoverflow 中提出问题时,删除重复的数据和代码执行,以及您所面临的预期结果或问题。 Without these none of the community member can help you out.没有这些,社区成员都无法帮助您。 hope this will help you.希望这会帮助你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用xlwt将python数据导出到Excel? - How do you export python data to excel using xlwt? 如何使用For Loops将数据从Excel导出到Python? - How do you export data from Excel into Python using For Loops? 如何使用 python 找到 excel 中列中的数字之间的差异? - How do you find the difference between numbers in a column in excel using python? 如何使用python将数据集导出到excel? 不断收到以下错误“str object has no attribute 'to_excel'” - How do you export a data set to excel using python? Keep getting the following error "str object has no attribute 'to_excel'" 如何使用 Python 将德语变音符号导出到 excel 文件中 - How to export German umlauts into excel file using Python 如何使用xlwt将python列表导出到excel文件中? - How to export python list into excel file using xlwt? 如何使用python将字符串拆分为带引号的句子和数字 - How do you split a string into quoted sentence and numbers using python 如何使用 python 找到前 x 个素数? - How do you find the first x prime numbers using python? 您如何使用 python 在现有的 excel 文件中使用多列 append 新行? - How do you append a new row in an excisting excel file using python with multiple columns? 在Python中使用变量名导出excel文件 - Export an excel file using a variable name in Python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM