TypeError: unhashable type: 'slice'

import numpy as npimport pandas as pd# Importing the datasetdataset = pd.read_csv('50_Startups.csv')y=dataset.iloc[:, 4]X=dataset.iloc[:, 0:4]# Encoding categorical datafrom sklearn.preprocessing import LabelEncoder, OneHotEncoderlabelencoder_X = LabelEncoder()X[:, 3] = labelencoder_X.fit_transform(X[:, 3])

X is a data frame and can’t be accessed via slice terminology like X[:, 3]. You must access via iloc or X.values. However, the way you constructed X made it a copy… so. I’d use values

# Importing the librariesimport numpy as npimport matplotlib.pyplot as pltimport pandas as pd# Importing the dataset# dataset = pd.read_csv('50_Startups.csv')dataset = pd.DataFrame(np.random.rand(10, 10))y=dataset.iloc[:, 4]X=dataset.iloc[:, 0:4]# Encoding categorical datafrom sklearn.preprocessing import LabelEncoder, OneHotEncoderlabelencoder_X = LabelEncoder()#  I changed this lineX.values[:, 3] = labelencoder_X.fit_transform(X.values[:, 3])