1

Is there a way to select all str, float and int columns in a dataframe, excluding columns holding objects like dicts and class instances? df.select_dtypes(include=[int, float, str]) raises TypeError due to str and df.select_dtypes(include=[int, float, object]) doesn't distinguish between strings and other objects.

import pandas as pd

df = pd.util.testing.makeMixedDataFrame()

df["E"] = df.A.map(lambda x: {"E": x**2})

df.dtypes

df.select_dtypes(include=object)
>>>     C   E
0   foo1    {'E': 0.0}
1   foo2    {'E': 1.0}
2   foo3    {'E': 4.0}
3   foo4    {'E': 9.0}
4   foo5    {'E': 16.0}
Janosh
  • 3,392
  • 2
  • 27
  • 35

0 Answers0