1

Dataset: The name of dataframe I am working on is 'f500'. Here is the first five rows in the dataframe

Goal: Select data with only numeric value


What I've tried:

1) I tried to use boolean array to filter out the non-numeric values and there was no error.

numeric_only_bool = (f500.dtypes != object)

boolean array

2) However, when I tried to do indexing with that boolean array, an error occurs.

numeric_only = f500[:, numeric_only_bool]

error message

I saw index-wise(row-wise) boolean indexing examples but could not find column-wise boolean indexing. Can anyone help how to fix this code?

Thank you in advance.

0

1 Answer 1

2

Use DataFrame.loc:

numeric_only = f500.loc[:, numeric_only_bool]

Another soluion with DataFrame.select_dtypes:

#only numeric
numeric_only = f500.select_dtypes(np.number)
#exclude object columns
numeric_only = f500.select_dtypes(exclude=object)
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.