0

In Python 3 and pandas I have this dataframe:

import pandas as pd

ano_2016_exec = pd.read_excel('emendas/emendas_executadas_autores_2016.xls',sheet_name='Sheet1', decimal = ",")

ano_2016_exec.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 10428 entries, 0 to 10427
Data columns (total 9 columns):
Autor               10427 non-null object
Emenda              10427 non-null object
UO_Ajustada         10427 non-null object
Funcional           10427 non-null object
Acao_e_Subtitulo    10427 non-null object
Valor_aprovado      10428 non-null float64
Empenhado           10428 non-null float64
Depesa_Executada    10428 non-null float64
Pago                10428 non-null float64
dtypes: float64(4), object(5)
memory usage: 733.3+ KB

In the original file, the columns "Valor_aprovado", "Empenhado", "Despesa_Executada" and "Pago" are numbers with a decimal point -> ",". Example:

3647087716,31449 -> represents in decimal "." 3,647,087,716.31449
498820,7 -> 498,820.7

But the loaded file transformed these columns into float, with notation:

colunas_selecionadas = ["Valor_aprovado", "Empenhado", "Depesa_Executada", "Pago"] ano_2016_exec[colunas_selecionadas].head()

Valor_aprovado  Empenhado   Depesa_Executada    Pago
0   9.100292e+09    7.268573e+09    7.268573e+09    3.647088e+09
1   6.471218e+06    6.471218e+06    6.471218e+06    0.000000e+00
2   1.200000e+06    3.421430e+05    3.421430e+05    1.710710e+05
3   7.471218e+06    6.713361e+06    6.713361e+06    0.000000e+00
4   2.000000e+05    1.000000e+05    1.000000e+05    1.000000e+05

Like:

7.268573e+09 
3.647088e+09
6.471218e+06

I want these numbers to appear in my dataframe with two decimals and not in notation. Like this:

7,268,572,739.83
3,647,087,716.31

Please, is this possible?

How should I properly load the data file 'emendas_executadas_autores_2016.xls'?

Reinaldo Chaves
  • 965
  • 4
  • 16
  • 43
  • 1
    If you want the numbers to appear fully, you can just do `df.Pago.astype(str)` but they'll be converted to strings. Also, you can change pandas options to show the full number with 2 decimal places (e.g. `pd.options.display.float_format = '{:.2f}'.format`). Finally, if you need the commas and points, you can do a custom formatting function (please refer: https://stackoverflow.com/questions/29663252/format-pandas-integers-for-display) – rafaelc Apr 20 '18 at 21:14

1 Answers1

1

Set a locale that interprets numbers in this way. The Spanish locale does so: es_ES.UTF-8

Use this parameter in the same way as listed here - but for the opposite purpose: How do I use Python to convert a string to a number if it has commas in it as thousands separators?

fasta
  • 361
  • 1
  • 5