目前,我有代碼可以為每個串列創建一個新的 Pandas Dataframe,然后將每個串列列印到 Excel 中自己的列。
將串列組合成單個資料框然后將每個串列添加到其自己的 Excel 列的方法是什么?
代碼
df_cc = pd.DataFrame({'Captions': cc_list})
wb = load_workbook(path)
ws = wb['Sheet1']
df_fname = pd.DataFrame({'Filename': filename_list})
wb = load_workbook(path)
ws = wb['Sheet1']
# Write to the excel sheet
for index, row in df_cc.iterrows():
cell = 'C%d' % (index 2)
ws[cell] = row[0]
for index, row in df_fname.iterrows():
cell = 'D%d' % (index 2)
ws[cell] = row[0]
uj5u.com熱心網友回復:
這應該有效。確保安裝所需的 deps ( pip install xlwt)。
df = pd.DataFrame({
'Captions': cc_list,
'Filename': filename_list
})
df.to_excel('test.xls')
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/504066.html
