#NEWLINE# def text_vectorizer( data , cols , method = 'bow' , **args ) : #NEWLINE# #INDENT# "\n    Wrapper for ngramBOW and ngramTFIDF that can be applied to multiple columns \n    of a pandas DataFrame\n    \n    Args:\n        data - a pandas DataFrame\n        cols - a list of colum names on which to run vectorization\n        method - 'bow' or 'tfidf' \n        **args - args to pass to vectorizor\n    \n    Returns:\n        A scipy sparse CSR matrix concatentaed for each column vectorization \n        from data\n    " #NEWLINE# if ( method == 'bow' ) : #NEWLINE# #INDENT# vectorizer = ngramBOW #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if ( method == 'tfidf' ) : #NEWLINE# #INDENT# vectorizer = ngramTFIDF #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# raise ValueError ( ( 'Unkown vectorization method %s' % vectorizer ) ) #NEWLINE# #UNINDENT# #UNINDENT# return sparse . hstack ( [ vectorizer ( data [ col ] , ** args ) for col in cols ] ) . tocsr ( )