简体   繁体   English

直接列行excel

[英]Direct column and row excel

In my Excel sheet I have columns with names for example in first row has got name Smith, it gives me one specific information about product, in next column I have the same name Smith and it gives me other specific information about product.在我的 Excel 工作表中,我有列名称,例如第一行的名称为 Smith,它为我提供了有关产品的特定信息,在下一列中,我具有相同的名称 Smith,它为我提供了有关产品的其他特定信息。
I would like to write a program which outputs a new Excel file where data is united and name Smith is in one row instead of two or more with all specific information I need from other columns.我想编写一个程序,它输出一个新的 Excel 文件,其中数据是统一的,并且名称 Smith 在一行而不是两行或更多行中,其中包含我需要从其他列获得的所有特定信息。

I really do not know how to start with this.我真的不知道如何开始。
What I can make is print whole specific row or column:我可以做的是打印整个特定的行或列:

for row in sheet.rows:
    print(row[2].value)

for column in sheet.columns:
    print(column[2].value)
import pandas as pd
import os
from openpyxl import load_workbook

path = "C:\\My files\\Staff\\Project\\ProjektExcelPython\\test_files\\"
book = load_workbook(os.path.join(path, "PlikExcelDoKonwersji.xlsx"))
#spreadsheet_file = pd.read_excel(os.path.join(path, "PlikExcelDoKonwersji.xlsx"), engine='openpyxl', header = 1)

sheet = book['sheet1']

for row in sheet.rows:
    print(row[2].value)

for column in sheet.columns:
    print(column[2].value)

There are many excel packages which one will be the most efficient to start creating such program?有许多 excel 包,哪一个最有效地开始创建此类程序?

输出数据

My idea is to create a loop which iterate every row and get specific information and add to the columns in other Excel.我的想法是创建一个循环,迭代每一行并获取特定信息并添加到其他 Excel 中的列。
If name is the same add to the same row in other Excel.如果名称相同,则添加到其他 Excel 中的同一行。

I also think about making list of dictionary with data using JSON, I saw sth like this around.我还考虑使用 JSON 使用数据制作字典列表,我看到了这样的东西。

Instead of using Python script, you should use pivot table, in pivot table, put product name column in pivot column field and qty column in value field and remaing column will goes to row pivot field. Instead of using Python script, you should use pivot table, in pivot table, put product name column in pivot column field and qty column in value field and remaing column will goes to row pivot field. for formatting of data Design tab>report layout>(tabluar form, repeat) and (Subtotal>do not show sub total) –用于数据格式设计选项卡>报告布局>(表格形式,重复)和(小计>不显示小计)-

row data for example are as follow行数据例如如下

在此处输入图像描述

final summary最后总结

在此处输入图像描述

second full details images第二个完整的细节图像

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM