Skip to content
Advertisement

How to create a list that groups columns according to their type?

I have a dataframe that contains over 200 columns. I need to create two lists that group columns by type. Rather than creating this list manually I tried different methods that did not work:

JavaScript

or:

JavaScript

or :

JavaScript

Can anyone help me solve this problem?

Advertisement

Answer

I believe that for this question you can use df.select_dtypes like this :

JavaScript

Another way to do this would be using the list comprehension :

JavaScript
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement