阿桂天山的小工具:我将16个Excel文件中31万多条数据拆分成318个文件

1.话不多说,先上图看效果

2.技术说明及实用源码

2.1)python+flask+pandas , 由于我的开发环境版本问题,为了能读xls,xlsx,但又不想升级,只能通过xlrd 1.2.0读取xls,xlsx文件再转换成dict字典格式,再通过 data = pd.DataFrame(dict_data)实现类型转换

2.2)实用代码,保证不丢任何一行数据,亲测验证,绝对好用

复制代码
            data = pd.DataFrame(dict_data)

            row_num, column_num = data.shape  # 数据共有多少行,多少列
            print('the sample number is %s and the column number is %s' % (row_num, column_num))
            # 1000行分割
            for i in range(0, (row_num // 1001)+1):
                save_data = data.iloc[i * 1000:(i + 1) * 1000, :]  # 每隔1000循环一次
                split_num = split_num+1
                splitfilename = os.path.join(config.SPLIT_FOLDERFILES, 'split_' + str(split_num) + '.xls')
                print("split file name:",splitfilename)
                save_data.to_excel(splitfilename, sheet_name='Sheet1',  index=False) 
                filenames = filenames + 'split_' + str(split_num) + '.xls '
            filenames = filenames + ';'

2.3)其实重点就三行代码

1000行分割

for i in range(0, (row_num // 1001)+1):
save_data = data.iloc[i * 1000:(i + 1) * 1000, :] # 每隔1000循环一次

save_data.to_excel(splitfilename, sheet_name='Sheet1', index=False)

如果对你有帮助,给个赞吧

相关推荐
Dxy12393102163 分钟前
Elasticsearch 聚合入门:像 Excel 透视表一样分析数据
elasticsearch·excel
一位代码35 分钟前
Excel | .xls 与 .xlsx 文件的区别及使用 Excel 打开 CSV 文件出现乱码的解决办法
excel
CodeCraft Studio1 小时前
Excel处理控件Aspose.Cells教程:使用C#在Excel中创建树状图
前端·c#·excel·aspose·c# excel库·excel树状图·excel sdk
悟能不能悟3 小时前
vue导出excel文件
前端·vue.js·excel
CodeCraft Studio3 小时前
国产化Excel开发组件Spire.XLS教程:以Python编程方式在Excel中高亮重复值
开发语言·python·excel·spire.xls·excel自动化·excel高亮重复值·python处理excel
喝汽水的猫^17 小时前
Java实现Excel 导出(多 Sheet、复杂格式)
java·excel
小费的部落19 小时前
Excel 在Sheet3中 匹配Sheet1的A列和Sheet2的A列并处理空内容
java·前端·excel
缺点内向20 小时前
如何在 C# 中重命名 Excel 工作表并设置标签颜色
开发语言·c#·excel
wtsolutions1 天前
Sheet-to-Doc: Automate Document Generation with Excel Data and Word Templates
word·excel·wtsolutions
wtsolutions1 天前
Sheet-to-Doc:用Excel数据和Word模板自动生成文档
excel·wps·wtsolutions