在Python 3和pandas中我有这个数据帧:
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
在原始文件中,列&#34; Valor_aprovado&#34;,&#34; Empenhado&#34;,&#34; Despesa_Executada&#34;和&#34;帕果&#34;是带小数点的数字 - &gt; &#34;&#34 ;.例如:
3647087716,31449 -> represents in decimal "." 3,647,087,716.31449
498820,7 -> 498,820.7
但是加载的文件将这些列转换为float,并带有符号:
colunas_selecionadas = [&#34; Valor_aprovado&#34;,&#34; Empenhado&#34;,&#34; Depesa_Executada&#34;,&#34; Pago&#34;] ano_2016_exec [colunas_selecionadas]。头()
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
像:
7.268573e+09
3.647088e+09
6.471218e+06
我希望这些数字出现在我的数据框中,带有两位小数而不是表示法。像这样:
7,268,572,739.83
3,647,087,716.31
拜托,这可能吗?
我应该如何正确加载数据文件&#39; emendas_executadas_autores_2016.xls&#39;?
答案 0 :(得分: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?