Saturday, June 14, 2014

Use Pandas and Decision Tree.

The most powerful decision tree module I know is DecisionTree: DecisionTree . 
Decision Tree needs a specific input format:


The question here is how to use Pandas to prepare such a .csv input. 

Keywords: 
  • DataFrame.one_column.astype( str ). 
  • to_csv( filename, quoting = 2) . 
First you need to load the csv with read_csv
You need to save the csv with quoting = QUOTE_NONMERIC. See the following explanation copied from https://docs.python.org/2/library/csv.html . 

You also need to convert the index from numeric to alphabetic, by : 

df.index = df.index.astype(str) 

thanks. 



No comments:

Post a Comment