为什么这会返回“太多索引器"? [英] Why does this return 'Too Many Indexers'?

查看:67
本文介绍了为什么这会返回“太多索引器"?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的代码是:

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)
classifier.predict(Xtest)
y

到达设置目标"部分时,编译器返回错误索引器过多".我直接从文档中提取了这个语法,所以我不确定可能有什么问题.csv 使用这些数据列标题进行组织.

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.

推荐答案

没有你的数据,很难验证.但是,我立即怀疑您需要传递一个 numpy 数组而不是 DataFrame.

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.

试试这个来提取它们:

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

这篇关于为什么这会返回“太多索引器"?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆