human
I am working on the file "SparkML - 02 Credit Default.ipynb".
The first task is:
As I can see, there are number of columns of string type - checking_balance, credit_history etc.
Let me define a function that take a catgorical column and pass it through StringIndexer and OneHotEncoder it gives back a dataframe with same column name as the original categorical column. It reurns a new dataframe that contains categorical column replaced by OneHotEncoded vector. 
Find all columns of String datatype
Transform each string column type into OneHotEncoded value and collect distinct values for each categorical column in list as shown below.
Can you write Python code for it?
 Can you provide a Python code to find all columns of String datatype?
assistant
#Here is Python code to find all columns of String datatype
.

cols = credit.columns
cols.remove("default")
cols

from pyspark.ml import Model, Estimator 

class DFOneHotEncoderModel(Model):
    
    def get_col_labels(self):
        
        cols = []
        feature_columns = [c for c in self.columns if not c == self.label_column]
        
        for col in feature_columns:
            if col in self.categorical_fields:
                string_indexer, _ = self.categorical_fields[col]
                values = string_indexer.labels
                values = values[:-1] if self.drop_last else values
                values = [col + "_" + v for v in values]
                cols.extend(values)
            else:
                cols.append(col) 
            
        return cols
    
    def transform(self, df, params= None):
        
        for colname in self.categorical_fields:
            string_indexer, one_hot_encoder = self.categorical_fields[colname]
        
            df = string_indexer.transform(df)
            df = df.drop(colname)
            df = df.withColumnRenamed(colname + "_idx", colname)

            if one_hot_encoder:
                df = one_hot_encoder.transform(df)
                df = df.drop(colname)
                df = df.withColumnRenamed(colname + "_ohe", colname)
                
        return df
        
class DFOneHotEncoder(Estimator):
    
    def __init__(self, label_column, categorical_fields= None,  one_hot = True, drop_last = True):
        self.categorical_fields = None
        self.one_hot = one_hot
        self.drop_last = drop_last
        self.label_column = label_column 
        
        if not categorical_fields is None:
            self.categorical_fields = dict([(c, None) for c in categorical_fields])     

    def fit(self, df):
        cols = df.columns
        if self.categorical_fields is None:
            self.categorical_fields = dict([(col, None) for col, dtype in df.dtypes if dtype == "string"])
        
        
        for colname in self.categorical_fields:
            string_indexer =...