a_attribute_list = ['one', 'two', 'three', 'six']
b_attribute_list = ['x', 'y']
a_membership = [np.reshape(np.array(df2['a'].values == elem).astype(np.
    float64), (num_rows, 1)) for elem in a_attribute_list]
b_membership = [np.reshape((df2['b'].values == elem).astype(np.float64), (
    num_rows, 1)) for elem in b_attribute_list]
c_column = np.reshape(df2['c'].values, (num_rows, 1))
design_matrix_a = np.hstack(tuple(a_membership))
design_matrix_b = np.hstack(tuple(b_membership))
design_matrix = np.hstack((design_matrix_a, design_matrix_b, c_column))
for row in design_matrix:
    pass
Python Pandas: how to turn a DataFrame with "factors" into a design matrix for linear regression?