<s> import pandas as pd <EOL> from quandl . errors . quandl_error import ColumnNotFound <EOL> class DataMixin ( object ) : <EOL> def to_pandas ( self , keep_column_indexes = [ ] ) : <EOL> data = self . to_list ( ) <EOL> if data and isinstance ( data , list ) and not isinstance ( data [ <NUM_LIT:0> ] , list ) : <EOL> data = [ data ] <EOL> if '<STR_LIT>' in self . meta . keys ( ) : <EOL> df = pd . DataFrame ( data = data , columns = self . columns ) <EOL> for index , type in enumerate ( self . column_types ) : <EOL> if type == '<STR_LIT>' : <EOL> df [ self . columns [ index ] ] = df [ self . columns [ index ] ] . apply ( pd . to_datetime ) <EOL> else : <EOL> df = pd . DataFrame ( data = data , columns = self . column_names ) <EOL> df [ self . column_names [ <NUM_LIT:0> ] ] = df [ self . column_names [ <NUM_LIT:0> ] ] . apply ( pd . to_datetime ) <EOL> df . set_index ( self . column_names [ <NUM_LIT:0> ] , inplace = True ) <EOL> df . index . name = str ( df . index . name ) <EOL> if len ( keep_column_indexes ) > <NUM_LIT:0> : <EOL> self . _validate_col_index ( df , keep_column_indexes ) <EOL> keep_column_indexes = list ( [ x - <NUM_LIT:1> for x in keep_column_indexes ] ) <EOL> df = df [ keep_column_indexes ] <EOL> return df <EOL> def to_numpy ( self ) : <EOL> return self . to_pandas ( ) . to_records ( ) <EOL> def to_csv ( self ) : <EOL> return self . to_pandas ( ) . to_csv ( ) <EOL> def _validate_col_index ( self , df , keep_column_indexes ) : <EOL> num_columns = len ( df . columns ) <EOL> for col_index in keep_column_indexes : <EOL> if col_index > num_columns or col_index < <NUM_LIT:1> : <EOL> raise ColumnNotFound ( '<STR_LIT>' <EOL> % col_index ) </s>
