python - Why does apply change dtype in pandas dataframe columns -


i have following dataframe:

import pandas pd import numpy np df = pd.dataframe(dict(a = np.arange(3),                           b = np.random.randn(3),                           c = ['foo','bar','bah'],                           d = pd.timestamp('20130101')))  print(df)             b    c          d 0  0 -1.087180  foo 2013-01-01 1  1 -1.343424  bar 2013-01-01 2  2 -0.193371  bah 2013-01-01 

dtypes columns:

print(df.dtypes)             int32 b           float64 c            object d    datetime64[ns] dtype: object 

but after using apply changes object:

print(df.apply(lambda x: x.dtype))    object b    object c    object d    object dtype: object 

why dtypes coerced object? thought in apply columns should taken in account.

pandas 0.17.1
python 3.4.3

you can use parameter reduce=false , more info here:

print (df.apply(lambda x: x.dtype, reduce=false))              int32 b           float64 c            object d    datetime64[ns] dtype: object 

Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -