I have the following df
, where there are new line characters \n
in column Data
, as shown below.
import pandas as pd
import xlsxwriter
df = pd.DataFrame({'ID': ['111', '222', '222'],
'Data': ['Population\nDensity','Population\nDensity','Population\nDensity\nArea']})
print(df)
ID Data
0 111 Population\nDensity
1 222 Population\nDensity
2 222 Population\nDensity\nArea
While exporting this df
to Excel, I want line breaks at \n
. It should look like:
I sought some help from here
, using xlsxwriter
but didn't work out.