def delete_files(self): ''' This function deletes all waveform data .csv when convert_all is run NO INPUTS OR OUTPUTS ''' folder = Globals.getCsvDir() for the_file in os.listdir(folder): file_path = os.path.join(folder, the_file) try: if os.path.isfile(file_path): os.unlink(file_path) except Exception, e: print e raise
def write_data_to_csv(self, song_data, song_name, genre, column_labels): ''' This function writes the song's feature row data into a csv file for modeling INPUT: song_data = 1d numpy array of floats containing song feature data; song_name (string); genre (string); column_labels = 1d numpy array of strings, song feature labels OUTPUT: NONE ''' csv_dir = Globals.getCsvDir() song_data = song_data.tolist() song_data.append(song_name) song_data.append(genre) column_names = [str(lab) for lab in column_labels] column_names.append("Song Name") column_names.append("Label") with open(csv_dir + "\\" + song_name + '.csv', 'wb') as csvfile: writer = csv.writer(csvfile, delimiter=',') writer.writerow(column_names) writer.writerow(song_data)
def df_stitcher(self): dir = Globals.getCsvDir() ''' This loads all of the outputted csv data from convert_all into the pandas data frame for analysis. It returns just the pandas data frame INPUT: none OUTPUT: pandas data frame containing feature data ''' ''' this could also go into the Modeler file/class ''' file_list = [f for f in listdir(dir) if isfile(join(dir, f))] df = pd.DataFrame() for file_name in file_list: try: df_dum = pd.read_csv(dir + "\\" + file_name) except: continue df = df.append(df_dum, ignore_index=True) df = df.dropna() return df