I have a pandas DataFrame
that I would like to write to Excel. For one column, I have data values that are comma-delimited strings, like "val1,val2"
or "val1,val2,val3"
. When I write that column, I would like to replace the commas with the equivalent of pressing ALT-ENTER
in Excel, so that there are line breaks between the values. So, my first example would display as val1
, then a break within the cell, then val2
, and so forth. You can also do this in Excel by making the cell a formula and putting &"char(10)"&
between each value.
I see how I could do this by coding up formulas via XLSXWriter and writing cells individually. However I'm hopefully (or lazily) wondering whether there's a way to encode the breaks right into the data so that they would all come out via a simple call to to_excel()
on the DataFrame
.