Home > Net >  How to parse the Pandas output to float
How to parse the Pandas output to float

Time:03-18

i'm using Pandas in python, and i'm trying to get only the value of this variable 'teste', but the pandas only return the entire thing. I just wanna the value like '0.0', how can i parse this value to float?

Current code:

teste = df.loc[df['NUMERO_DOC'].astype(str).astype(int) == 2, 'DOCS_RECEBIDOS_NUMERO']
teste.head()

Output:

0    0.0
Name: DOCS_RECEBIDOS_NUMERO, dtype: float64

CodePudding user response:

Use .iloc[0] to the the first actual value of a Series:

>>> teste.head().iloc[0]
0.0

CodePudding user response:

Use squeeze to reduce the dimension:

  • When you squeeze a Dataframe of 1 column, you transform it as a Series.
  • When you squeeze a Series of 1 row, you transform it as a scalar value.
>>> df.loc[df['NUMERO_DOC'].astype(str).astype(int) == 2, 'DOCS_RECEBIDOS_NUMERO'].squeeze()
0.0
  • Related