Presently, I have code that creates a new Pandas Dataframe per list and then prints each list to its own column in Excel.
What would be the way to combine the lists into a single Dataframe and then add each list to its own Excel column?
Code
JavaScript
x
18
18
1
df_cc = pd.DataFrame({'Captions': cc_list})
2
wb = load_workbook(path)
3
ws = wb['Sheet1']
4
5
df_fname = pd.DataFrame({'Filename': filename_list})
6
wb = load_workbook(path)
7
ws = wb['Sheet1']
8
9
10
# Write to the excel sheet
11
for index, row in df_cc.iterrows():
12
cell = 'C%d' % (index + 2)
13
ws[cell] = row[0]
14
15
for index, row in df_fname.iterrows():
16
cell = 'D%d' % (index + 2)
17
ws[cell] = row[0]
18
Advertisement
Answer
This should work. Make sure to install required deps (pip install xlwt
).
JavaScript
1
6
1
df = pd.DataFrame({
2
'Captions': cc_list,
3
'Filename': filename_list
4
})
5
df.to_excel('test.xls')
6