1
私はPythonとScikitを学びます。私はいくつかの簡単な練習をしています。特定のケースでは、私は次のコードを実行します。Pythonでのシリーズのスライシングとインデックス付け
import pandas as pd
df = pd.read_csv('SMSSpamCollection',delimiter='\t',header=None) # from UCIMachineLearningRepository http://archive.ics.uci.edu/ml/datasets/SMS+Spam+Collection
import numpy as np
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.linear_model.logistic import LogisticRegression
from sklearn.cross_validation import train_test_split, cross_val_score
X_train_raw, X_test_raw, y_train, y_test = train_test_split(df[1], df[0])
を私が印刷:
print(X_test_raw[0:5])
出力:シリーズX_test_rawのその後
3035 Get ready for <#> inches of pleasure...
2577 In sch but neva mind u eat 1st lor..
3302 RCT' THNQ Adrian for U text. Rgds Vatian
90 Yeah do! Don‘t stand to close tho- you‘ll catc...
2355 R we going with the <#> bus?
Name: 1, dtype: object
私はインデックスを作成しています一つずつ最初の要素を:
X_test_raw[0]
次いで
'Go until jurong point, crazy.. Available only in bugis n great world la e buffet... Cine there got amore wat...'
X_test_raw[1]
'Ok lar... Joking wif u oni...'
アウト次いで
X_test_raw[2]
アウト
アウト何が起こっているのですか?最初の5要素のシーケンスをスライスしているときと、このシーケンスの各要素を別々にインデックスしているときに、異なる値が返されるのはなぜですか?シリーズの3D要素のインデックスを作成するときにキーエラーメッセージが表示されるのはなぜですか?
あなたのアドバイスは、使用がX_test_raw[2]
あなたがindex=2
でrow
を取得しようとした場合