AttributeError: у объекта DataFrame нет атрибута target - PullRequest
0 голосов
/ 30 сентября 2018
    Traceback (most recent call last):
  File "data_visualization.py", line 14, in <module>
    y = df.target
  File "C:\Users\Aeryes\AppData\Local\Programs\Python\Python36\lib\site-packages\pandas\core\generic.py", line 4376, in __getattr__
    return object.__getattribute__(self, name)
AttributeError: 'DataFrame' object has no attribute 'target'

Я продолжаю получать эту ошибку, когда запускаю следующий код или пытаюсь использовать df.target в любой ситуации:

x = df.text
y = df.target
from sklearn.cross_validation import train_test_split
SEED = 2000
x_train, x_validation_and_test, y_train, y_validation_and_test = train_test_split(x, y, test_size=.02, random_state=SEED)
x_validation, x_test, y_validation, y_test = train_test_split(x_validation_and_test, y_validation_and_test, test_size=.5, random_state=SEED)
print("Train set has total {0} entries with {1:.2f}% negative, {2:.2f}% positive".format(len(x_train), 
                                            (len(x_train[y_train == 0]) / (len(x_train)*1.))*100,(len(x_train[y_train == 1]) / (len(x_train)*1.))*100))
print("Validation set has total {0} entries with {1:.2f}% negative, {2:.2f}% positive".format(len(x_validation), 
                                            (len(x_validation[y_validation == 0]) / (len(x_validation)*1.))*100,(len(x_validation[y_validation == 1]) / (len(x_validation)*1.))*100))
print("Test set has total {0} entries with {1:.2f}% negative, {2:.2f}% positive".format(len(x_test), 
                                            (len(x_test[y_test == 0]) / (len(x_test)*1.))*100, (len(x_test[y_test == 1]) / (len(x_test)*1.))*100))

Как я могу исправить эту ошибку и продолжить визуализацию данных?

df.head () по запросу:

                                                text
0  awww that bummer you shoulda got david carr of...
1  is upset that he can not update his facebook b...
2  dived many times for the ball managed to save ...
3     my whole body feels itchy and like its on fire
4  no it not behaving at all mad why am here beca...
...