Why does apply change dtype in pandas dataframe columns

后端 未结 1 815
旧巷少年郎
旧巷少年郎 2020-12-10 14:37

I have the following dataframe:

import pandas as pd
import numpy as np
df = pd.DataFrame(dict(A = np.arange(3), 
                         B = np.random.randn         


        
相关标签:
1条回答
  • 2020-12-10 15:41

    You can use parameter reduce=False and more info here:

    print (df.apply(lambda x: x.dtype, reduce=False))
    
    A             int32
    B           float64
    C            object
    D    datetime64[ns]
    dtype: object
    

    In newer versions of pandas is possible use:

    print (df.apply(lambda x: x.dtype, result_type='expand'))
    
    0 讨论(0)
提交回复
热议问题