I have this DataFrame on pandas:
import pandas as pd
df = pd.DataFrame({'CARGO': {53944: 'Driver',
57389: 'Driver',
60851: 'Driver',
64322: 'Driver',
67771: 'Driver'},
'DATE': {53944: '05/2015',
57389: '06/2015',
60851: '07/2015',
64322: '08/2015',
67771: '09/2015'},
'DESCRICAO': {53944: '\\Salario R$ 788,00\nGratificacao Adicional R$ 251,00\nGRATIFICAÇÃO R$ 512,00\nINSS R$ -104,00',
57389: '\\Salario R$ 788,00\nGratificacao Adicional R$ 251,00\nGRATIFICAÇÃO R$ 512,00\nINSS R$ -104,00',
60851: '\\Salario R$ 788,00\n1/3 de Ferias R$ 516,95\nGratificacao Adicional R$ 251,00\nGRATIFICAÇÃO R$ 512,00\nINSS R$ -104,00',
64322: '\\Salario R$ 788,00\nGratificacao Adicional R$ 251,00\nGRATIFICAÇÃO R$ 512,00\nINSS R$ -104,00',
67771: '\\Salario R$ 788,00\nGratificacao Adicional R$ 225,90\nGRATIFICAÇÃO R$ 512,00\nINSS R$ -104,00'},
'NOME': {53944: 'John Smith',
57389: 'John Smith',
60851: 'John Smith',
64322: 'John Smith',
67771: 'John Smith'}})
It renders this output:
How can I set up pandas or Jupyter so it will: 1. display plaintext 2. accept line break ('\n')
This opens up some interesting possibilities, like highliting some text on the dataframe html. Here is my try:
yelds:
(by the way, I got added some stuff on custom.css from Henry Hammond(https://github.com/HHammond/PrettyPandas), so that´s why headers and indexes are grey.
You can try these things out, replace the new line character with html line break tag
<br>
and explicitly using.to_html()
andHTML
for the display, and also set themax_colwidth
to be-1
so that the long line will not be truncated when converting tohtml
:The first part of the problem was solved.
On markdown, $ represents the start of a formula on mathjax. The solution is to inser a backslash before the symbol. Here is the snippet for pandas:
.
I wasn´t able to make a new line inside the cell..
Expanding on Psidom's excellent answer, you can encapsulate it in a re-usable function. This way you won't alter your dataframe permanently either: