【python】合并表格

本代码兼顾了合并sheet与合并表格的功能

import os
import pandas as pd
def combine_sheet(excel_path, number):
    #excel_path is str and num is the sequence number of the excel
    excel = pd.read_excel(excel_path, sheet_name = None, header = None)
    keys = list(excel.keys())
    excel_contact = pd.DataFrame()
    for i in keys:
        excel_sheet = excel[i]
        excel_contact = pd.concat([excel_contact, excel_sheet])
    excel_contact.to_excel(‘vocabulary{}.xlsx‘.format(number), header= False, index=None)

def combine_excel(excels_path):
    #excel_path is a list of excel files‘ name
    excel_combination = []
    for i in excels_path:
        excel_combination.append(pd.read_excel(i, header=None))
    new_excel = pd.concat(excel_combination)
    new_excel.to_excel(‘vocabulary.xlsx‘, header = False, index=None)

os.chdir(‘C:\\Users\\11440\\OneDrive‘)
combine_sheet(‘词汇.xlsx‘, 1)
combine_sheet(‘词汇2.xlsx‘, 2)

excel_list = ["vocabulary1.xlsx", "vocabulary2.xlsx"]
combine_excel(excel_list)

原文地址:https://www.cnblogs.com/PKU-CD/p/12294164.html

时间: 2024-10-06 23:41:46

【python】合并表格的相关文章

合并表格

<html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>合并表格</title> <script> /////////////////////////////////////////////// //功能:合并表格 //参数:tb-需要合并的表格ID //参数:colLen

python合并文本文件示例代码

python合并文本文件示例代码. python实现两个文本合并employee文件中记录了工号和姓名cat employee.txt: 100 Jason Smith200 John Doe300 Sanjay Gupta400 Ashok Sharma bonus文件中记录工号和工资cat bonus.txt: 100 $5,000200 $500300 $3,000400 $1,250要求把两个文件合并并输出如下, 处理结果:400 ashok sharma $1,250 100 jaso

dsplay:table页面合并表格

在实际项目中经常会遇到合并表格的情形,现在我将自己合并的方法写出来,供大家教参一下,顺便自己也作个备忘. <%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" &qu

(原创) cocos2d-x 3.0+ lua 学习和工作(4) : 公共函数(6): 合并表格:table.merge

这里的函数主要用来做:合并表格.参考资料为quick_cocos. 星月倾心贡献~~~ --[[ -- 将 来源表格 中所有键及值复制到 目标表格 对象中,如果存在同名键,则覆盖其值 -- example local tDest = { a = 1, b = 2 } local tSrc = { c = 3, d = 4 } table.merge( tDest, tSrc ) -- tDest = { a = 1, b = 2, c = 3, d = 4 } -- @param tDest 目

JS自动合并表格

1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 2 <html xmlns="http://www.w3.org/1999/xhtml"> 3 <head> 4 <meta http-equiv="

使用jquery合并表格中相同文本的相邻单元格

一.效果 二.代码 <!DOCTYPE HTML> <html> <head> <title>Example</title> <meta charset="utf-8"/> <style></style> <script src="js/jquery-2.1.4.min.js"></script> </head> <body>

使用 Python 合并多个格式一致的 Excel 文件

一 问题描述 最近朋友在工作中遇到这样一个问题,她每天都要处理如下一批 Excel 表格:每个表格的都只有一个 sheet,表格的前两行为表格标题及表头,表格的最后一行是相关人员签字.最终目标是将每个表格的内容合并到一个 Excel 表格中,使之成为一张表格.在她未咨询我之前,每天复制粘贴这一类操作占用了她绝大部分时间.表格样式如下: 二 需求分析 根据她的描述,最终需求应该是这样的:在这一批表格中选取任意一个表格的前两行作为新表格的标题与表头,将这两行内容以嵌套列表的形式插入一个名为 data

利用python合并两个文件

1格式如下 在做利用zabbix的api来批量添加主机的时候,需要处理ip和hostname,在借用别人写的py程序的基础上,自己有改装了以下脚本,为自己使用.需要时ip和hostname为一个统一格式. $ cat ip.txt 1.1.1.1 2.2.2.2 3.3.3.3 4.4.4.4 $ cat hostname.txt tx-1 tx-2 tx-3 tx-4 最后需要合并为如下格式 1 tx-1,1.1.1.1 2 tx-2,2.2.2.2 3 tx-3,3.3.3.3 4 tx-4

Python以表格的形式打印占用内存Top10的程序列表

此题目涉及到Python对进程的操作.for循环计数循环次数.排序与打印表格等,题目比较简单,效果图如下: 代码如下: #!/usr/bin/python # encoding: utf-8 # -*- coding: utf8 -*- """ Created by PyCharm. File:               LinuxBashShellScriptForOps:performanceOps.py User:               Guodong Crea