comment vérifier l'dtype d'une colonne en python pandas

J'ai besoin d'utiliser d'autres fonctions pour traiter numérique des colonnes et des colonnes de la chaîne. Ce que je fais maintenant est vraiment stupide:

allc = list((agg.loc[:, (agg.dtypes==np.float64)|(agg.dtypes==np.int)]).columns)
for y in allc:
    treat_numeric(agg[y])    

allc = list((agg.loc[:, (agg.dtypes!=np.float64)&(agg.dtypes!=np.int)]).columns)
for y in allc:
    treat_str(agg[y])    

Est-il une façon plus élégante de le faire? E. g.

for y in agg.columns:
    if(dtype(agg[y]) == 'string'):
          treat_str(agg[y])
    elif(dtype(agg[y]) != 'string'):
          treat_numeric(agg[y])
  • string n'est pas un dtype
InformationsquelleAutor James Bond | 2014-03-27