Search code examples
pythonjupyterdata-sciencenameerror

Python Jupyter Pandas NameError: name 'data' is not defined


These are my Libraries

import pandas as pd
import numpy as np
import seaborn as sns

These are the other one

from sklearn import linear_model
from sklearn.model_selection import train_test_split

When i try to run this command


x = data.iloc[:,:-1]
y = data['Class']

this Error is showing

NameError Traceback (most recent call last)
<ipython-input-13-431e580384e5> in <module>
----> 1 x = data.iloc[:,:-1]
      2 y = data['Class']
NameError: name 'data' is not defined

Solution

  • You skipped out a step: defining the "data" variable. I'm assuming your data variable is your dataframe.

    This link will help you understand how to load your dataset on python: https://www.listendata.com/2017/02/import-data-in-python.html?m=1