TAGS :Viewed: 9 - Published at: a few seconds ago

[ Why does this return 'Too Many Indexers'? ]

My code is:

import pandas as pd
import numpy as np
from sklearn import svm

name = '../CLIWOC/CLIWOC15.csv'
data = pd.read_csv(name)

# Get info into dataframe and drop NaNs
data = pd.concat([data.UTC, data.Lon3, data.Lat3, data.Rain]).dropna(how='any')

# Set target
X = data.loc[:, ['UTC', 'Lon3', 'Lat3']]
y = data['Rain']

# Partition a test set
Xtest = X[-1]
ytest = y[-1]
X = X[1:-2]
y = y[1:-2]

# Train classifier
classifier = svm.svc(gamma=0.01, C=100.)
classifier.fit(X, y)

Arriving at the 'set target' section, the compiler returns the error 'Too Many Indexers'. I lifted this syntax directly from the documentation, so I'm unsure what could be wrong. The csv is organized with these headers for columns of data.

Answer 1

Without your data, it is hard to verify. My immediate suspicion, however, is that you need to pass a numpy array instead of a DataFrame.

Try this to extract them:

# Set target
X = data.loc[:, ['UTC', 'Lon3', 'Lat3']].values
y = data['Rain'].values