Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Write data present in list to a column in excel sheet using xlxs writer module

I have two lists defined as:

Column1=[1,2,3,4]
Column2=[5,6,7,8]

I want to append the Column1 list to first column of an Excel sheet and the Column2 list to the second column of the Excel sheet. Excel sheet would look like:

enter image description here

My Code So Far:

from xlxswriter import*
workbook=Workbook('Ecl.xlxs')
Report_Sheet=workbook.add_worksheet()
for row_ind,row_value in enumerate(Column1):
    print row_ind,row_value
    Report_Sheet.write('A',Column1)#i want something similar to this

So each list should be appended to each column.

like image 488
user1681102 Avatar asked Dec 24 '22 18:12

user1681102


1 Answers

You could try with pandas like this:

import pandas as pd
df = pd.DataFrame.from_dict({'Column1':[1,2,3,4],'Column2':[5,6,7,8]})
df.to_excel('test.xlsx', header=True, index=False)

The test.xlsx will be like the one you need.

Update:

import pandas as pd
Column1 = [1,2,3,4]
Column2 = [5,6,7,8]
df = pd.DataFrame.from_dict({'Column1':Column1,'Column2':Column2})
df.to_excel('test.xlsx', header=True, index=False)
like image 166
Tiny.D Avatar answered Jan 05 '23 18:01

Tiny.D