# Import packages import numpy as np import pandas as pd # Data df = pd.DataFrame({"Country" : ["France", "Spain", "Germany", "Spain", "Germany", "France"], "Age" : [34, 27, 30, 32, 42, 30], "Purchased" : ["No", "Yes", "No", "No", "Yes", "Yes"]}) df Out[1]: Country Age Purchased 0 France 34 No 1 Spain 27 Yes 2 Germany 30 No 3 Spain 32 No 4 Germany 42 Yes 5 France 30 Yes # Checking data type df.dtypes Out[2]: Country object Age int64 Purchased object dtype: object # Saving CATEGORICAL Variables cat_col = [c for i, c in enumerate(df.columns) if df.dtypes[i] in [np.object]] cat_col Out[3]: ['Country', 'Purchased']
source share