<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def to_kv(expr, columns=None, kv_delim=':', item_delim=',', kv_name='kv_col'):
 """ Merge values in specified columns into a key-value represented column. :param DataFrame expr: input DataFrame :param columns: the columns to be merged. :param str kv_delim: delimiter between key and value. :param str item_delim: delimiter between key-value pairs. :param str kv_col: name of the new key-value column :return: converted data frame :rtype: DataFrame :Example: name k1 k2 k3 k5 k7 k9 0 name1 1.0 3.0 Nan 10.0 Nan Nan 1 name2 Nan 3.0 5.1 Nan Nan Nan 2 name3 7.1 Nan Nan Nan 8.2 Nan 3 name4 Nan 1.2 1.5 Nan Nan Nan 4 name5 Nan 1.0 Nan Nan Nan 1.1 name kv_col 0 name1 k1=1.0,k2=3.0,k5=10.0 1 name2 k2=3.0,k3=5.1 2 name3 k1=7.1,k7=8.2 3 name4 k2=1.2,k3=1.5 4 name5 k2=1.0,k9=1.1 """

    if columns is None:
        columns = [expr._get_field(c) for c in expr.schema.names]
        intact_cols = []
    else:
        columns = [expr._get_field(c) for c in utils.to_list(columns)]
        name_set = set([c.name for c in columns])
        intact_cols = [expr._get_field(c) for c in expr.schema.names if c not in name_set]

    mapped_cols = [c.isnull().ifelse(Scalar(''), c.name + kv_delim + c.astype('string')) for c in columns]
    reduced_col = reduce(lambda a, b: (b == '').ifelse(a, (a == '').ifelse(b, a + item_delim + b)), mapped_cols)
    return expr.__getitem__(intact_cols + [reduced_col.rename(kv_name)])