[英]i want to save a particular column into a new excel sheet in python
如果这是电子表格,那么我想制作一个仅包含product id
的新电子表格:
transaction id product id
1001 1
1002 2
1003 3
到目前为止我编写的代码我能够打印一个特定的列
import openpyxl as xl
from openpyxl import Workbook
wb = xl.load_workbook('transactions.xlsx')
sheet = wb['Sheet1']
book = Workbook()
x = input("row name")
y=int(x)
book.save("sample.xlsx")
for row in sheet.rows:
print(row[y].value)
为什么不直接使用to_excel 。 它不那么复杂:
df[['product_id']].to_excel('sample.xlsx', index = False) #Keeping index = True will have an extra row with index
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.