2

I am trying to format a pandas DataFrame value representation. Basically, all I want is to get the "Thousand" separator on my values.

I managed to do it using the pd.style.format function. It does the job, but also "breaks" all my table original design.

here is an example of what is going on: Example

Is there anything I can do to avoid doing it? I want to keep the original table format, only changing the format of the value.

PS: Don't know if it makes any difference, but I am using Google Colab.

Henry Ecker
  • 34,399
  • 18
  • 41
  • 57
Miguel
  • 157
  • 1
  • 11

2 Answers2

1

In case anyone is having the same problem as I was using Colab, I have found a solution:

.set_table_attributes('class="dataframe"') seems to solve the problem

More infos can be found here: https://github.com/googlecolab/colabtools/issues/1687

Miguel
  • 157
  • 1
  • 11
0

For this case you could do:

pdf.assign(a=pdf['a'].map("{:,.0f}".format))
U13-Forward
  • 69,221
  • 14
  • 89
  • 114
  • Is there any way I can do this using a dictionary? My example is only changing the format of a single column, but in real life I got a few more – Miguel Sep 10 '21 at 04:29