[英]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.