0

I need all numbers in my pandas dataframes converted to german number notation. It means there should be thousands decimal dot and a comma for fractions.

example.:

52.634,99

I can do it easily the other way around, first comma, then dot:

pd.options.display.float_format = '{:,.2f}'.format

Why is it not possible to use it this way?

pd.options.display.float_format = '{:.,2f}'.format

error:

ValueError: Format specifier missing precision
stanvooz
  • 378
  • 1
  • 10

1 Answers1

1

converted to german number notation

This is task for locale built-in module, you can use it following way:

import locale
import pandas as pd
locale.setlocale(locale.LC_NUMERIC, 'de_DE')
pd.options.display.float_format = lambda x:locale.format_string('%.2f',x,True)
df = pd.DataFrame({'x':[5663499e-2]})
print(df)

output

          x
0 56.634,99

Explanation: use german (de_DE) numeric convention, '%.2f' is 2 digits after ,, x is value itself, True is use thousands sep. For futher discussion see locale.format_string in docs.

Daweo
  • 21,690
  • 3
  • 9
  • 19