[英]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.