locale.setlocale(locale.LC_ALL, 'pt_BR.UTF-8')
filtered_data['Receita Total'] = filtered_data['Receita Total'].apply(lambda x: locale.currency(x, grouping=True))
filtered_data['Margem Final'] = filtered_data['Margem Final'].apply(lambda x: f"{x:.2f}%")
How can I format my columns as currency without them ending up in object/string format? I want them to be numeric so that I can sort the numbers from highest to lowest without them being in alphabetical order.
My table has this format
print(filtered_data.dtypes)
row.names object
data object
ano float64
razaoSocial object
cnpj object
entidadeId object
status_final object
total_exames int64
receita_total float64
margem_final float64
When I format the column it changes to object, but I don't want that to happen
filtered_data['receita_total'] = filtered_data['receita_total'].apply(lambda x: locale.currency(x, grouping=True))
filtered_data['margem_final'] = filtered_data['margem_final'].apply(lambda x: f"{x:.2f}%")
print(filtered_data.dtypes)
row.names object
data object
ano float64
razaoSocial object
cnpj object
entidadeId object
status_final object
total_exames int64
receita_total object
margem_final object
dtype: object
locale.format_currency()which is the only way to get thousands separators on bsd libc derived implementations. Not sure whether it will work on musl libc based systems.