import random标签:批量,excel,random,spot,生成,phone,num,time,data From: https://www.cnblogs.com/creeperrr/p/17136770.html
import os
import pandas as pd
import time
#excel转换vcf网址
#https://xlsx2vcf.kefuxx.com/
time_tuple = time.localtime(time.time())
nowtime = "{}年{}月{}日".format(time_tuple[0],time_tuple[1],time_tuple[2])
def get_phone_num():
second_spot = random.choice([3,4,5,7,8])
third_spot = {3:random.randint(0,9),
4:random.choice([5,7,9]),
5:random.choice([i for i in range(10) if i!=4]),
7:random.choice([i for i in range(10) if i not in[4,9]]),
8:random.randint(0,9),}[second_spot]
remain_spot=random.randint(9999999,100000000)
phone_num = "1{}{}{}".format(second_spot,third_spot,remain_spot)
return phone_num
print(get_phone_num())
# file = open('1.vcf', 'w')
# for i in range(100):
# file.writelines(get_phone_num()+'\n')
# file.close()
f = pd.ExcelWriter('./1.xlsx')
data = pd.DataFrame(columns=['姓名','电话'])
for i in range(100):
data.loc[i]=nowtime,get_phone_num()
print(data)
data.to_excel(f,index=False)
f.save()