Integer numbers in pandas python "dataframe"


I import a document to jupiter and enter normal with whole numbers, I apply a formula to group, add and then subtract and the product leaves all the numbers with decimals and exponentials.

How do I get only whole numbers ???

::::::: attached code ::::::::::


cond1_df = (
    .groupby(["move_id/id"], as_index=False)
        balance=lambda row: - row.debit
        resultado=lambda row: row.balance < -0.000001



asked by Yan Chirino 12.04.2018 в 00:25

1 answer


The columns are originally of the float type, the use of scientific notation is used by default to show very large or very small values in order to represent the DataFrame in the always limited screen space without having excessively wide columns.

A very simple example:

>>> import pandas as pd

>>> df = pd.DataFrame({"a":[1214514552.0, 14455145556552.0]})

>>> df
0  1.214515e+09
1  1.445515e+13

You can force a certain format at the time of representing the floats by using the display.float_format option and using the format specification mini language :

>>> pd.set_option('display.float_format', '{.1f}'.format)
>>> df
0     1214514552.0
1 14455145556552.0

You can also use pd.options.display.float_format = '{:.1f}'.format .

In this case with :.1f force the floats with a single decimal. This does not affect the data itself , only the way it is displayed.

answered by 12.04.2018 / 01:15