Error in the code: "'target'"

Soham1087

Banned
Joined
May 31, 2022
Messages
17
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Location
India
Activity points
185
Hello,

I'm presently working on a supervised learning project and am having trouble resolving a KeyError. I've put my data into a pandas DataFrame, double-checked the column names, and followed every step outlined here. When I try to access the target variable column, however, I receive the following error:
Code:
KeyError: 'target'
I double-checked the column names and confirmed that 'target' exists in the DataFrame. I'm still not clear why this KeyError is happening. Could you possibly assist me in determining what is causing this problem?

Here's a bit of the code that's creating the problem:
Code:
import pandas as pd

# Assuming I have already loaded the data into a DataFrame called 'df'

# Split the data into features (X) and target labels (y)
X = df.drop(columns=['target'])
y = df['target']
I'd be grateful for any ideas or recommendations on how to resolve this KeyError. Thank you in advance for your assistance!
 

Cookies are required to use this site. You must accept them to continue using the site. Learn more…