The sum of a column of type "float64" in pandas returns a float instead of numpy.float64

I have a dataframe in pandas. I take the column sum of the data frame as:

x = data['col1'].sum(axis=0)
print(type(x))

I checked that the column col1in the datadataframe is of type float64. But the type xis equal <class 'float'>. I expected the type to xbe numpy.float64.

What am I missing here?

pandas version is '0.18.0', numpy version is '1.10.4', python version is 3.5.2

+4
source share
1 answer

This is similar to what pandas handles nans. When I set skipna=Falsein a method sum, I get a numpydatatype type

import pandas as pd
import numpy as np

type(pd.DataFrame({'col1':[.1,.2,.3,.4]}).col1.sum(skipna=True))
#float

type(pd.DataFrame({'col1':[.1,.2,.3,.4]}).col1.sum(skipna=False))
#numpy.float64

sum nansum pandas/core/nanops.py, .

from pandas.core.nanops import nansum

type(sum(np.arange(10.0)))
# numpy.float64

type(nansum(np.arange(10.0)))
# float

nansum numpy.float64 float, . nansum, , , , .

+3

Source: https://habr.com/ru/post/1655885/


All Articles