简体   繁体   English

如何使用 Python 将数据从一个 Excel 工作表复制到同一工作簿的另一工作表?

[英]How to copy data from One Excel sheet to another sheet for same Workbook Using Python?

I specifically am trying to copy certain cells from one sheet in Excel workbook, and paste them into certain cells in same Excel workbook for differnt sheet.我特别试图从 Excel 工作簿中的一张工作表中复制某些单元格,并将它们粘贴到同一 Excel 工作簿中的某些单元格中以获取不同的工作表。 How to copy the stored contents into a particular sheet, in another sheet for same workbook.I have two sheets in first sheet data and values are mentioned in below input.如何将存储的内容复制到特定工作表中,在同一工作簿的另一张工作表中。我在第一个工作表数据中有两张工作表,下面的输入中提到了值。 Then in second sheet for same excel get values only for the particular header.然后在相同 excel 的第二张表中仅获取特定 header 的值。 Any clue how I may go about this?任何线索我怎么可能 go 关于这个? Also, is it possible to make the range defined for a CellRange conditional on certain cell properties?此外,是否可以使为 CellRange 定义的范围以某些单元格属性为条件?

I would really appreciate any help, Thank you.我真的很感激任何帮助,谢谢。 all.全部。

Below Input are in Sheet1 Input |Student ID|下面的输入在 Sheet1输入|学生 ID| Student Name|学生姓名| Java|爪哇| Python|蟒蛇| OS |操作系统 | .NET| .NET| DBMS|数据库管理系统| C | C | C++ | C++ | VB | VB | Practical 1 |实用 1 | Practical 2|实用2| Total|总计| Average|平均|

|1 | |1 | Anu |阿努 | 100 | 100 | 80 | 80 | 70 | 70 | 60 | 60 | 85 | 85 | 74| 74| 60 |100 | 60 |100 | 90 | 90 | 89 | 89 | 808 | 808 | 80.8 | 80.8 |

|2 | |2 | Bala |巴拉 | 100 | 100 | 100 | 100 | 100| 100| 70 | 70 | 70 | 70 | 80| 80| 80 | 80 | 90 | 90 | 90 | 90 | 100 | 100 | 880 | 880 | 88 | 88 |

|3 | |3 | Chitra |奇特拉 | 80 | 80 | 70 | 70 | 40 | 40 | 60 | 60 | 50 | 50 | 45| 45| 55 | 55 | 65 | 65 | 70 | 70 | 80 | 80 | 615 | 615 | 61.5 | 61.5 |

Output Output

预期产出

You'll need to transform data as you need and store it another sheet:您需要根据需要转换数据并将其存储在另一个工作表中:

#Columns in student.xlsx : Name,Gender,DOB,Maths,Physics,Chemistry,English,Biology,Economics,History,Civics
import pandas as pd
pd.read_excel(open('student.xlsx', 'rb'),
              sheet_name='Sheet1')
af = df.melt(id_vars="Name","Gender","DOB"],var_name="Subject",value_name="Marks")
result  = af.sort_values(by="Name")
result.to_excel('student.xlsx,sheet_name='Sheet2')

暂无
暂无

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

相关问题 使用Python(和DataNitro)将单元格从一个Excel工作簿中的特定工作表复制到另一个Excel工作簿中的特定工作表 - Using Python (and DataNitro) to copy cells from a particular sheet in one Excel workbook, to a particular sheet in another Excel workbook 如何使用python将Excel工作表复制到具有相同格式的另一个工作簿 - How to copy excel sheet to another workbook with same format using python 如何使用 python 将 excel 工作簿中的内容复制到另一个工作簿而不丢失 excel 格式 - How to copy contents from a sheet of an excel workbook to another workbook without loosing the excel formatting using python 如何使用python将数据从一个工作表添加到另一个工作簿中的现有工作表而不覆盖其他工作表的数据? - How to add data using python from one sheet to an existing sheet in another workbook without overwriting other sheet's data? 将数据从一个 Excel 工作表复制到另一个 Excel 工作表 - Copy data from one excel sheet to another excel sheet 如何在 Python 中将 Excel 工作表复制到另一个工作簿 - How to copy over an Excel sheet to another workbook in Python 如何使用 pandas 将数据从一张 excel 工作表循环复制到另一个具有相同文件名的工作表 - How to looping copy data from one excel sheet to another with same filename with pandas 如何使用 openpyxl 库将列从一张 excel 表复制到另一张 python? - How can I copy columns from one excel sheet to another with python using openpyxl Library? 使用python将Excel工作簿表合并为一个 - Combining excel workbook sheet into one using python Python 代码不在 Excel 工作表中写入输出,但能够从同一工作簿中的另一个工作表获取输入 - Python code not writing output in excel sheet but is able to take input from another sheet in same workbook
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM