Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

get columns based on dtype pandas

>>df.select_dtypes(include='object').columns

Index(['C', 'D'], dtype='object')
Comment

get columns by type pandas

In [2]: df = pd.DataFrame({'NAME': list('abcdef'),
    'On_Time': [True, False] * 3,
    'On_Budget': [False, True] * 3})

In [3]: df.select_dtypes(include=['bool'])
Out[3]:
  On_Budget On_Time
0     False    True
1      True   False
2     False    True
3      True   False
4     False    True
5      True   False

In [4]: mylist = list(df.select_dtypes(include=['bool']).columns)

In [5]: mylist
Out[5]: ['On_Budget', 'On_Time']
Comment

get columns based on dtype pandas

>>df.select_dtypes(include='object').columns

Index(['C', 'D'], dtype='object')
Comment

get columns by type pandas

In [2]: df = pd.DataFrame({'NAME': list('abcdef'),
    'On_Time': [True, False] * 3,
    'On_Budget': [False, True] * 3})

In [3]: df.select_dtypes(include=['bool'])
Out[3]:
  On_Budget On_Time
0     False    True
1      True   False
2     False    True
3      True   False
4     False    True
5      True   False

In [4]: mylist = list(df.select_dtypes(include=['bool']).columns)

In [5]: mylist
Out[5]: ['On_Budget', 'On_Time']
Comment

PREVIOUS NEXT
Code Example
Python :: train split 
Python :: how to urllib3 
Python :: django fixtures. To dump data 
Python :: use a dictionary to make a column of values 
Python :: change matplotlib fontsize 
Python :: standardise columns python 
Python :: lexicographic order python 
Python :: finding the rows in a dataframe where column contains any of these values python 
Python :: python summary() 
Python :: onehotencoder pyspark 
Python :: decision tree algorithm python 
Python :: python unzip a zip 
Python :: day name in python 
Python :: hex python add 0 
Python :: python Correlation matrix of features 
Python :: python remove empty lines from file 
Python :: change text in legend matplotlib 
Python :: list to dataframe 
Python :: how to check libraries in python 
Python :: find size of mongodb collection python 
Python :: apply same shuffle to two arrays numpy 
Python :: delete dictionary key python 
Python :: python remove repeated elements from list 
Python :: python date range 
Python :: render django 
Python :: most common value in a column pandas 
Python :: System.Windows.Forms.DataGridView.CurrentRow.get returned null. c# 
Python :: copy website python 
Python :: python convert from float to decimal 
Python :: how to invert plot axis python 
ADD CONTENT
Topic
Content
Source link
Name
9+2 =