Limit to Python 3 decimals

Asked

Viewed 1,130 times

-1

I made a script in python and need help.

As you can see, a spreadsheet in excel is opened, treats the data and returns to another spreadsheet.

When opening the new spreadsheet, the numbers get huge and the date also, for example, 1.333333 and I would like it to stay 1.33.

    put = pd.read_excel('Operacao_inicial.xlsm', sheet_name='Rastreador_PUT', decimal=",", thousands='.', inex_col=(), false_values='NaN', keep_default_na=False, header=8)
    
    put =pd.DataFrame(put, columns=['STRIKE','ATIVO','VENC.','Robo PUT','Real Time','TIR (%)','Strike VS Cot. (%)','Money','Negocios'])

    put['STRIKE'] = pd.to_numeric(put['STRIKE'], errors='coerce')
    put['VENC.'] = pd.to_datetime(put['VENC.'], errors='coerce')
    put['Real Time'] = pd.to_numeric(put['Real Time'], errors='coerce')
    put['TIR (%)'] = pd.to_numeric(put['TIR (%)']*100, errors='coerce')
    put['Strike VS Cot. (%)'] = pd.to_numeric(put['Strike VS Cot. (%)']*100, errors='coerce')
    put['Money'] = pd.to_numeric(put['Money'], errors='coerce')
    put['Negocios'] = pd.to_numeric(put['Negocios'], errors='coerce')

    put.to_excel('Robo_operacional.xlsx', index=0)

schedule.every(5).minutes.do(coletar_dados)

while True:
    schedule.run_pending()
    time.sleep(5)

1 answer

1


To round the decimals is something very simple... Just use the round! It looks like it’s simple:

round(1232.21, 2) #o primeiro argumento é o numero a ser arredondado e o segundo são as casa decimais

You can put a variable as argument too, for example:

num =  123.32
print(round(num, 2)

I hope I’ve helped!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.