Python之Excel编辑-[小试牛刀]将表格内容按照类别进行统计和拆分

python菜鸟excel教程-Python操作Excel的Xlwings教程(一) 在日常的工作中,我们或多或少的都要和Excel打交道。甚至在一些领域,某一些业务人员的主要工作就是处理Excel表格,处理大量的Excel数据并生成一系列的报表。对于程序员朋友们来说,更喜欢以代码的形式来处理Excel,从而实现一些Excel中的一些函数功能。那么在Python中处理Excel的模块(或者说叫第三方库)有哪些呢,主要如下:Xlrd:xlrd支持.xls、.xlsx Excel文件的... 阅读详情

Pandas的DataFrame有个groupby的方法,能够按照指定的列进行分组,这样能够很方便的按照指定的类别对表格项进行分类统计。
下面来看一个例子。

任务1:将所有明细表进行合并,并按照产品类别拆分成多个页面

解决办法:
第一步:使用Pandas DataFrame的append方法,将所有的明细表中的内容合并到一个表格中
第二步:使用Pandas DataFrame的groupby方法,指定某个列,将表格的所有内容进行分类

app = xw.App(visible=True, add_book=False)
    file_list = os.listdir(file_path)
    table = pd.DataFrame() #创建一个空的DataFrame
    for file in file_list:
        if '~$' in file:
            continue
        if file.split('.')[-1] != 'xlsx':
            continue
        wb = app.books.open(file_path + '\\' + file)
        for sheet in wb.sheets:
            values = sheet.range('A1').expand().options(pd.DataFrame, header=1, index=False).value
            data = values.reindex(columns=['品类','产品','价格'])#提取所关注的列
            table = table.append(data, ignore_index = True)#将新提取的内容合并到列表中

        wb.save()
        wb.close()
    table = table.groupby('品类') #指定按照品类进行分类

    newbook = app.books.add()
    for idx, group in table: #从分类后的列表中逐组提取内容并写入到一个新的sheet中
        new_worksheet = newbook.sheets.add(idx)
        new_worksheet['A1'].options(index=False).value = group
    newbook.save(file_path+'\\物品分类.xlsx')
    newbook.close()
    app.quit()

基于上述方法,还可以很方便的对每组内容进行统计处理

【Python】操作Excel之分类汇总       情系雷锋月,爱洒三月天。三月是雷锋月,抓住他的小尾巴,留下一点爱心,分享一下近来几天我学习python操作Excel的体会与技巧:对表格进行分类汇总。 有一个Excel表 (乱序)         我想要操作的就是把所有科目编码为'10101'的'借方金额'与'贷方金额'分别累加求和,最终得到一个下面这样的表格            这个操作用专业术语说就是:分类汇总... 阅读详情

相关推荐

用 Python 对 Excel 表格内数据进行去重、分类,标记异常及分析

介绍一个用Python对Excel表格数据进行去重、分类、异常处理及分析的实例。

三二班_周同学 1万+

python xlwings追加数据_Python学习随笔:使用xlwings设置和操作excel多行多列数据以及设置数据字体颜色填充色对齐方式的方法...

一、关于整行整列数据读写的问题在《Python学习随笔:使用xlwings读取和操作Excel文件》介绍了一次读写整行和整列的方法,整行数据写入时可以简单将读取的赋值语句交换一下等号左右两边的操作数据,但在写入整列数据时不能简单用该方式赋值,而是在列选择中加上“options(transpose=True)”的方式,且无需使用expand方法,否则还是操作的行数据,哪怕expand的参数为‘dow...

weixin_39874809的博客 3203

xlwings文档学习--第7章Data structures 数据结构

In [1]:# 导入基本包 import xlwings as xw import numpy as np import pandas as pd In [4]:# 打开目标文件 wb = xw.Book(r'C:\Users\Track1\PycharmProjects\xlwing\xlwings_if\xlwings_if.xlsm') In [5]:import datetime as ...

oldwayphone的博客 3924

python处理excel数据

文章目录前言一、用到的库是什么?二、execl表格的样式三、模块的使用1.引入模块2.读取excel表数据3.将写入excel表四、代码分析1.代码逻辑2.选出有用的股票号并与回报率关联3.将全部数据按照所需要的股票号进行分类4.将分类好的数据写入excel五、成果展示总结 前言 帮朋友做一份数据处理,但是由于对excel的不熟悉,所以还是使用了python去做。本文主要是简单的python处理excel数据,具体服务于特定形式的excel表格 一、用到的库是什么? xlrd 主要用于读取excel文

Fengziwen1的博客 4012

从MRF8P9040N数据手册到ADS仿真:手把手教你搞定LDMOS功放设计(附完整模型下载)

本文详细解析了MRF8P9040N LDMOS功率放大器的数据手册关键参数,并提供了在ADS中进行仿真的完整指南。从模型导入、直流工作点验证到负载牵引与阻抗匹配设计,逐步指导工程师完成高效功放设计。文章还包含调试技巧和常见问题解决方案,帮助优化射频功放性能。

weixin_27015733的博客 496

物流系统集成实战:从零开始用Java对接国际快递(DHL/FedEx/UPS)

本文详细介绍了如何使用Java技术栈对接DHL、FedEx和UPS三大国际快递巨头的API,构建高效、稳定的物流集成解决方案。内容涵盖认证机制、报文标准、多语言支持等关键点,并提供实战代码示例和最佳实践,帮助开发者快速实现国际快递系统集成。

efc1234567的博客 699

xlwings的使用

Color边框颜色和填充颜色不同,若指定RGB需要转换为HEX,调用rgb_to_int(),公式如下:Hex=R+G×256+B×65536。强大的转换器能处理绝大多数数据类型,如 字典、Numpy Array 和 Pandas DataFrame。文件 → 选项 → 信任中心 → 信任中心设置 → 信任对 VBA 工程对象模型的访问。指定位置是数据起始点,一行一行读写。按行列号读写(向下、向右数),如图。此宏运行的逻辑与同名.py的一致。LineStyle边框线型。Matplotlib图像。

weixin_50170972的博客 1358

Visual Tracker Benchamark傻瓜式教程(二)

问题  1 1  在调用main.m跑TRE和SRE时,因为会生成相应的.mat数据文件,如果跑完以后发现自己算法生成的.mat文件有问题,那么要把该文件删除,待找到错误原因后,重新生成相应的.mat文件。因为程序中写的是如果已经存在了.mat文件,例如已经存在car4_STC.mat文件,即使该文件中的数据有错误,但是重新跑时会默认该文件中的数据写完,不会重新写入数据 问题  2  b

mingbujingren的专栏 9929

Python批量处理行、列和单元格

知识延伸精确调整一个工作簿中所有工作表的行高与列宽 ——采购表.xlsx。

weixin_48719464的博客 2875

基于555定时器的D类功放设计:从PWM原理到无反馈电路实践

D类功放(数字功放)是一种高效率的音频放大技术,其核心原理是脉冲宽度调制(PWM)。它将输入的模拟音频信号转换为一系列高速开关的脉冲,通过控制功率开关管(如MOSFET)的通断,再经低通滤波器还原放大后的音频。相比传统AB类功放,其转换效率通常超过90%,显著降低了热能损耗。这项技术在追求高能效和小型化的现代音频设备中价值凸显,广泛应用于有源音箱、汽车音响和便携式设备。本文聚焦于一种独特的实现方案:以经典的555定时器芯片为核心,构建一个无整体负反馈的D类功放。通过剖析其PWM调制器、FET电压-电流转换级

weixin_30162121的博客 236

基于C#的工业机器人上位机控制程序开发(搭配松下PLC+MC协议)

基于C#的工业机器人上位机控制程序开发,核心是上位机与松下PLC的MC协议通信和机器人控制的安全逻辑,而不是单纯的界面编写。在工控现场,程序的稳定性和安全性永远是第一位的——比如解耦通信逻辑、处理跨线程问题、添加安全互锁、记录操作日志,这些都是保证产线稳定运行的关键。新手在学习时,建议先跟着步骤搭建好环境,跑通基础的PLC通信和机器人控制功能,再逐步尝试进阶优化。数据模型化、通信封装化、逻辑模块化、UI解耦化。

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 1250

使用Python批量进行数据分析

知识延伸1、sort_value()是pandas模块中DataFrame对象的函数,用于将数据区域按照某个字段的数据进行排序,这个字段可以是行字段,也可以是列字段。语法格式:批量降序排序一个工作簿中的所有工作表——产品销售统计表.xlsx批量排序多个工作簿中的数据——产品销售统计表(文件夹)

weixin_48719464的博客 4912

自动驾驶算法/规划决策控制算法面经汇总、学习路线、面经心得

自动驾驶算法学习路线,面试求职大全

qq_41667348的博客 1万+

Python之Excel编辑-[小试牛刀]将表格列分拆或合并

任务1:将表格指定列内容分拆成多列 将如下格式的表格中规格列的内容进行分拆,分解成长,宽,高 解决思路: 将数据读取成Pandas的DataFrame形式,然后采用字符串分割的方法对规格列的内容进行分割,并添加长,宽,高三列。 app = xw.App(visible=True, add_book=False) file_list = os.listdir(file_path) for file in file_list: if '~$' in file:

weixin_39028066的博客 332

【Inpho精品教程】Inpho简介、安装教程(附Inpho8安装包下载)

本文介绍Trimble旗下Inpho UASMaster航空摄影测量软件,涵盖其核心功能模块(如Match-AT、OrthoMaster、Summit Evolution等)及安装教程。文章详细说明了从安装到汉化破解的全过程,并提供Inpho 8.0.1安装包下载链接与提取码,适用于无人机摄影测量专业用户。

智慧空间实验室 1万+

Allegro如何把分离的线段变成封闭连续的图形

Allegeo支持把分离的线段变成封闭连续的图形,以下图为例,线段是分离的。Allegro如何把分离的线段变成封闭连续的图形。Find选择other segs 和Lines。Find选择other segs 和Lines。选择shape-compose shape。分离线段已经是连续封闭的shape形式了。框选图形,删除剩下的无用的分离线段。Find选择shapes。鼠标右击选择done。选择delete命令。鼠标右击选择done。

weixin_54787054的博客 6254

Python之Excel编辑-[小试牛刀]分拆和合并excel表格

任务1:表格拆分 将如下所示的一个excel表格,按照不同的品类分拆到不同的excel文件中。 解决思路: 遍历表格中每一行,按照品类来构造字典项,将表格的每一行作为字典的value进行保存。然后遍历不同的字典项,将不同的字典项写到不同的表格中。 app = xw.App(visible=True, add_book=False) file_list = os.listdir(file_path) for file in file_list: if file.startsw

weixin_39028066的博客 333

IEM模型,地表粗糙度模拟

利用微波反演土壤水分时候,利用IEM模型可以实现对随机地表的模拟

Python让Excel飞起来—批量进行数据分析

案例01 批量升序排序一个工作簿中的所有工作表 代码文件:批量升序排序一个工作簿中的所有工作表.py 数据文件:产品销售统计表.xlsx 每个表批量对销售利润进行升序排列: import xlwings as xw import pandas as pd app=xw.App(visible=True,add_book=False) workbook=app.books.open(r'C:\Users\MLoong\Desktop\22\产品销售统计表.xlsx') for i in wo.

Colorfully_lu的博客 4423

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

RU DOS版、EFI版32bit/64bit BIOS常用工具

DOS版、EFI版的RU工具,可用来查看IO、MEM、PCI、SMBIOS等资源。亲测在EFI SHELL下可用。

4 python数据分析基础——批量处理行、列和单元格

一、 精确调整多个工作簿的行高和列宽 二、批量更改多个工作簿的数据格式 三、批量替换多个工作簿的行数据 四、

简时刻的博客 2926

ssm框架搭建

这个是一个在idea上成功跑起来的ssm框架项目,保存在这里方便以后使用直接下载

Python之Excel编辑-[小试牛刀]表格内容统计处理

任务1:按物品种类进行统计 按物品种类对表格中的所有物品进行统计,并在表格中添加sheet表单写入统计结果 解决思路: 将表格内容读取成pandas DataFrame形式,然后使用pandas的统计功能进行数据统计处理 app = xw.App(visible=True, add_book=False) file_list = os.listdir(file_path) for file in file_list: if '~$' in file:

weixin_39028066的博客 338

5 python数据分析基础——批量进行数据分析(一)

一、批量升序排序一个工作簿中的所有工作表 二、筛选一个工作簿中的所有工作表数据 三、对多个工作簿中的工作表分别进行分类汇总 对一个工作簿中的所有工作表分别求和

简时刻的博客 2358

Python让Excel飞起来—批量处理行、列和单元格

案例01 精确调整多个工作簿的行高和列宽 ·代码文件:精确调整多个工作簿的行高和列宽.py ·数据文件:销售表(文件夹) 除了前面讲解的工作簿和工作表的批量操作,Python还可以对工作表中的行、列和单元格等元素进行批量设置。例如,要调整行高和列宽,可以使用xlwings模块的column_width和row_height属性,再加上for语句,就可以实现批量调整了。 调整为: 代码如下: import os import xlwings as xw file_pa...

Colorfully_lu的博客 1万+

pandas 取excel 中的某一列_Excel快速分表(xlwings+pandas)

Excel总表快速分表:step1: 读取exel数据到DataFramestep2: dataframe中数据进行筛选step3:将筛选完的数据存储到excel中工作中应用实例step1:读取Excel的数据到pandas 的Dataframe方法1:采用pandas,读取sheet1的内容到import pandas as pd excel_file = pd.ExcelFile(data...

weixin_39517054的博客 1555

dataframe 设置空值_2019-12-19(三)对DataFrame空值数据记录进行的各种选择(1)

'''上期回顾:学习对DataFrame数据记录进行各项选择前的初步和整体的了解。本次:我们将学习对DataFrame数据记录进行的各种选择!因为2019-12-16(二)我们有在DataFrame中修改了数据集的索引index的值,所以我们利用2019-12-13(一)所学的知识,重新将数据导入到DataFrame中'''##Pandas:数据分析包import pandas as pd#num...

weixin_39710106的博客 733

python中基本分类算法

# -*- coding: utf-8 -*- """ Created on Sun Oct 6 12:46:25 2019 @author: Administrator """ import os import numpy as np import pandas as pd from matplotlib import pyplot as plt #mse def mse_erro...

chenlei4366的博客 931

python 类型-Python数据类型详解

目录1、字符串2、布尔类型3、整数4、浮点数5、数字6、列表7、元组8、字典9、日期1、字符串1.1、如何在Python中使用字符串a、使用单引号(')用单引号括起来表示字符串,例如:str='this is string';print str;b、使用双引号(")双引号中的字符串与单引号中的字符串用法完全相同,例如:str="this is string";prin...

weixin_37988176的博客 3408
上一篇: pyecharts进行数据可视化--多图形组合拼装
下一篇: 树莓派-安装Jupyter遇到ffi.h文件缺失问题
weixin_39028066
博客等级 码龄9年 8粉丝 14原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值