ValueError: could not convert string to float: 'rec_id'
とエラーが出ました。
コードには
import numpy as np import pandas as pd import scipy as sp import pickle from scipy import fft from time import localtime, strftime import matplotlib.pyplot as plt from skimage.morphology import disk,remove_small_objects from skimage.filter import rank from skimage.util import img_as_ubyte import wave ########################### # Folder Name Setting ########################### folder = 'mlsp_contest_dataset/' essential_folder = folder+'essential_data/' supplemental_folder = folder+'supplemental_data/' spectro_folder =folder+'my_spectro/' single_spectro_folder =folder+'my_spectro_single/' dp_folder = folder+'DP/' ################################################### ## Read the Essential Data ## labels, training-test split,file_names etc. ################################################### # Each audio file has a unique recording identifier ("rec_id"), ranging from 0 to 644. # The file rec_id2filename.txt indicates which wav file is associated with each rec_id. rec2f = pd.read_csv(essential_folder + 'rec_id2filename.txt', sep = ',') # There are 19 bird species in the dataset. species_list.txt gives each a number from 0 to 18. species = pd.read_csv(essential_folder + 'species_list.txt', sep = ',') num_species = 19 # The dataset is split into training and test sets. # CVfolds_2.txt gives the fold for each rec_id. 0 is the training set, and 1 is the test set. cv = pd.read_csv(essential_folder + 'CVfolds_2.txt', sep = ',') # This is your main label training data. For each rec_id, a set of species is listed. The format is: # rec_id,[labels] raw = pd.read_csv(essential_folder + 'rec_labels_test_hidden.txt', sep = ';') #label = np.zeros(len(raw)*num_species) #label = label.reshape([len(raw),num_species]) label = np.zeros((len(raw),num_species)) for i in range(len(raw)): line = raw.iloc[i] labels = line[0].split(',') labels.pop(0) # rec_id == i #for c in labels[i]: #if(c =="?"): #label[i,c] = 1 label = pd.DataFrame(label) label['rec_id'] = cv.rec_id label['fold'] = cv.fold label['filename'] = rec2f.filename # Sparse training set # training species 1%--5%--20% spec_avg = label[label.fold ==0][:num_species].mean() spec_avg.sort_values(inplace=True) plt.plot(spec_avg,'go')
と書きました。
Tracebackには
/Users/XXX/anaconda/envs/py36/lib/python3.6/site-packages/skimage/filter/__init__.py:6: skimage_deprecation: The `skimage.filter` module has been renamed to `skimage.filters`. This placeholder module will be removed in v0.13. warn(skimage_deprecation('The `skimage.filter` module has been renamed ' Traceback (most recent call last): File "test1.py", line 67, in <module> plt.plot(spec_avg,'go') File "/Users/XXX/anaconda/envs/py36/lib/python3.6/site-packages/matplotlib/pyplot.py", line 3317, in plot ret = ax.plot(*args, **kwargs) File "/Users/XXX/anaconda/envs/py36/lib/python3.6/site-packages/matplotlib/__init__.py", line 1898, in inner return func(ax, *args, **kwargs) File "/Users/XXX/anaconda/envs/py36/lib/python3.6/site-packages/matplotlib/axes/_axes.py", line 1407, in plot self.add_line(line) File "/Users/XXX/anaconda/envs/py36/lib/python3.6/site-packages/matplotlib/axes/_base.py", line 1793, in add_line self._update_line_limits(line) File "/Users/XXX/anaconda/envs/py36/lib/python3.6/site-packages/matplotlib/axes/_base.py", line 1815, in _update_line_limits path = line.get_path() File "/Users/XXX/anaconda/envs/py36/lib/python3.6/site-packages/matplotlib/lines.py", line 989, in get_path self.recache() File "/Users/XXX/anaconda/envs/py36/lib/python3.6/site-packages/matplotlib/lines.py", line 676, in recache x = np.asarray(xconv, np.float_) File "/Users/XXX/anaconda/envs/py36/lib/python3.6/site-packages/numpy/core/numeric.py", line 531, in asarray return array(a, dtype, copy=False, order=order) ValueError: could not convert string to float: 'rec_id'
と表示されました。 'rec_id'には16.157895 の値が入っていて、配列全体をstring から float にキャストするにはどうしたら良いのでしょうか?どう書けば良いのでしょうか?
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
退会済みユーザー
2017/05/30 10:55
退会済みユーザー
2017/05/30 10:56