Categories
excel pandas.excelwriter python python-3.x word-wrap

Writing text wrapped Excel Files using Python

I am new to Python and I was practicing by processing some CSV files and making an excel file from them. So far I can get the excel file however, I am unable to wrap the cells via python. I have tried multiple ways but none of it would work. Perhaps it is because of my poor understanding of Python. Can anyone suggest me how can I wrap text while writing the excel file? And please explain the code along the way? The error that i am getting for the following code is:
‘str’ object has no attribute ‘alignment’

This is what I have done so far:

df=pd.DataFrame(list(zip(Dticketnumberlist,Dcategorylist)), 
columns=['Ticket', 'Category'])
writer = pd.ExcelWriter('Trial Version.xlsx', engine="xlsxwriter")
df.to_excel(writer, sheet_name="Sheet1")
workbook=writer.book
worksheet = writer.sheets['Sheet1']
wrap_alignment = Alignment(wrap_text=True)
cell.alignment = wrap_alignment