I'm formatting a data frame (or rather a styler object) to have all elements be of the same length and preceded by a dollar sign. However, in the output "excessive" spaces are removed, i.e. only one space remains between the number and the dollar sign regardless of how many digits the actual number contains. See below for an example.
import pandas as pd
df = pd.DataFrame([[123456, 1234.56], [123, 12345678.9123]])
df.style.format('${:15,.2f}')
Which gives the following output:
If I instead pad the numbers using zeroes
df.style.format('${:015,.2f}')
it gives the following output:
How come the padding is truncated when using spaces, but not when using 0's (or other characters such as '_' or '-')? What can I do to avoid this behavior?