Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Python
  3. Question
Python

Python typeerror: unhashable type: 'slice' for encoding categorical data

Asked by Adam Lipscomb Apr 13, 2021 1.8K views 1 answer
Share

About this question

 I am getting

TypeError: unhashable type: 'slice'

when executing the below code for encoding categorical data in Python. Can anyone please help?

# Importing the libraries 

import numpy as np 

import matplotlib.pyplot as plt 

import pandas as pd 

# Importing the dataset 

dataset = pd.read_csv('50_Startups.csv') 

y=dataset.iloc[:, 4] 

X=dataset.iloc[:, 0:4] 

# Encoding categorical data 

from sklearn.preprocessing import LabelEncoder, OneHotEncoder labelencoder_X = LabelEncoder() 

X[:, 3] = labelencoder_X.fit_transform(X[:, 3])

Your answer

1 Answer

More Python discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Python Blogs

Guides, tips and career advice on Python from JanBask experts.