功能未定义。 " NameErro:姓名'火车'没有定义"在jupyter python 3中

时间:2016-09-15 19:18:09

标签: python-3.x pandas jupyter

import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt

​def warn(*args, **kwargs): pass
import warnings
warnings.warn = warn

from sklearn.preprocessing import LabelEncoder
from sklearn.cross_validation import StratifiedShuffleSplit

train = pd.read_csv('..\input\train.csv')
test = pd.read_csv('..\input\test.csv')

def encode(train, test):
     le = LabelEncoder().fit(train.species) 
     labels = le.transform(train.species)           
     classes = list(le.classes_)                         
     test_ids = test.id                             

     train = train.drop(['species', 'id'], axis=1)  
     test = test.drop(['id'], axis=1)

     return train, labels, test, test_ids, classes

train, labels, test, test_ids, classes = encode(train, test)
train.head(5)

NameError                                 

Traceback (most recent call last) <ipython-input-10-08166fb1df95> in <module>()
     10     return train, labels, test, test_ids, classes
     11 
---> 12 train, labels, test, test_ids, classes = encode(train, test)
     13 train.head(5)

NameError: name 'train' is not defined

0 个答案:

没有答案