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}
2

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.