【python 平分切割】python切割数据成N等分,写入n个excel 文件

python切割数据成N等分,写入n个excel 文件

在这里插入图片描述

# -*- encoding=utf-8 -*-


import pandas as pd
import math

lists = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,11,12, 13, 14, 16, 17, 18, 19,20]
length = len(lists)
print(length)
n = 4
for i in range(n):
    one_list = lists[math.floor(i / n * length):math.floor((i + 1) / n * length)]
    # print(one_list)

    data=pd.DataFrame({'mobile':one_list})
    print(data)

    data.to_excel('F:/img_spam/切割/'+str(i+1)+'.xlsx',index=False)
E:\laidefa\python.exe F:/文本标签/文本防刷系统/读数据集.py
20
   mobile
0       0
1       1
2       2
3       3
4       4
   mobile
0       5
1       6
2       7
3       8
4       9
   mobile
0      10
1      11
2      12
3      13
4      14
   mobile
0      16
1      17
2      18
3      19
4      20

Process finished with exit code 0

切割180万txt手机号,均分为582等分。按数字递增的文件命名。输出excel

# -*- encoding=utf-8 -*-


import pandas as pd
import math

k1=pd.read_table('F:/img_spam/cell.txt',sep='\t')
print(k1.head())
lists=list(k1['mobile'])
# lists = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10,11,12, 13, 14, 16, 17, 18, 19,20]
length = len(lists)
print(length)
n = 582
for i in range(n):
    one_list = lists[math.floor(i / n * length):math.floor((i + 1) / n * length)]
    # print(one_list)
    data=pd.DataFrame({'mobile':one_list})
    print(data)
    data.to_excel('F:/img_spam/切割/'+str(i+1)+'.xlsx',index=False)
已标记关键词 清除标记
©️2020 CSDN 皮肤主题: 编程工作室 设计师:CSDN官方博客 返回首页