データを抽出する時に、"ValueError:labels ['arrival'] not contained in axis という エラーが発生して苦慮しております!
下記が今回、エラーの発生したソースコードでございます。
# -*- coding: utf-8 -*- import urllib2 import codecs import numpy as np import pandas as pd f1 = codecs.open('panda_1_1.csv', 'w', 'utf-8') #読み込ませるデータ data = pd.read_csv("temp_test_1_1.csv" , sep=",") # 特徴データとラベルデータを取り出す data_except_arrival = data.drop("arrival", axis=1) features = data_except_arrival.as_matrix() targets = data['arrival'].as_matrix() #== 1 #.strip() low_frequentry_data = data[data.arrival == 1].index low_frequentry_data_sample = data.loc[low_frequentry_data] pd.DataFrame(low_frequentry_data_sample) #print pd.DataFrame(low_frequentry_data_sample) sampling_size = len(data[data.arrival == 1]) #print ("sampling size : ",sampling_size) high_frequentry_data = data[data.arrival == 0].index # 出現頻度の小さいクラスに、大きいクラスの個数を合わせてランダムにデータを抽出する random_indices = np.random.choice(high_frequentry_data, sampling_size, replace=False) high_frequentry_data_sample = data.loc[random_indices] pd.DataFrame(high_frequentry_data_sample) #print pd.DataFrame(high_frequentry_data_sample) # データをマージする merged_data = pd.concat([high_frequentry_data_sample, low_frequentry_data_sample], ignore_index=True) pd.DataFrame(merged_data) print pd.DataFrame(merged_data) merged_data.to_csv('panda_1_1.csv', index=None)
読み込ませるデータ temp_test_1_1.csv は こちらでございます。
temp(0) temp(1) temp(2) temp(3) temp(4) temp(5) temp(6) temp(7) temp(8) temp(9) temp(10) temp(11) temp(12) arrival 0 0 4 8.1 13.1 12.3 9.1 9.2 6.4 6.6 6.3 6.5 6.9 1 0 6.8 3.7 9.9 16 7 5.3 4.9 5.1 5.1 5.2 4.7 4.7 1 0 3.4 30 61.4 27.8 11.5 11.7 11.9 12.8 13.4 14 14.5 15.6 0 0 3.4 25 9.1 48 38 20.4 17.7 18.3 15 14.6 14.2 14.9 0 0 6.8 9.9 19.7 12.8 13.6 14.3 14 14.2 15 14.3 14.5 15.3 1 0 3.4 25 34.5 156.1 107.4 84.6 59.3 63.2 67.7 65.7 67.2 69.2 0 0 0 37.6 92.2 198.7 137.7 125.3 99.2 90.1 93.8 92.4 93.8 90.9 0 0 0 5.5 12 27.9 28.4 26.9 25.9 27.5 27.4 27.8 27.4 28.7 0 0 0 4.3 1.4 1.1 1.3 1.5 1.7 1.8 1.8 1.8 1.8 1.8 0 0 0 50.1 61.4 118.1 57 58.7 32.5 35.1 38.3 39.5 40.3 42.9 0 0 0 25.6 88.4 88.4 47.1 76.8 70.6 70.6 76.7 81.4 78.9 80.2 0
ValueError:labels ['arrival'] not contained in axis
について、少し調べたのですが、列に空白があるのが原因とありましたので、.strip()を用いてみましたが
うまく動きませんでした。
先輩方の御教示、よろしくお願いいたします。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2017/07/29 00:31