Q:

Trying to create dummy variables using OnehotEncoder

I am learning machine learning, and I was trying to preprocess the data. and I came across an error.     X[:, 1] = X_label_encoder_1.fit_transform(X[:,1]) IndexError: index 1 is out of bounds for axis 1 with size 1. I tried everything but I couldn' get it.
# get the dependant and independent variables
X = dataset.iloc[:, 3:13].values
y = dataset.iloc[:, 13].values

X = X.reshape(-1, 1)
y = y.reshape(-1, 1)

# change the categorical values into numbers
X_label_encoder_1 = LabelEncoder()
X[:, 1] = X_label_encoder_1.fit_transform(X[:,1])
X_label_encoder_2 = LabelEncoder()
X[:, 2] = X_label_encoder_2.fit_transform(X[:,2])

onehotencoder = OneHotEncoder(categories=X[1])
X = onehotencoder.fit_transform(X).toarray()

A:

Here is how I would approach this:
# load 'pandas' library
import pandas as pd

# One-hot encode categorical variable
one_hot_column_name = pd.get_dummies(dataset_name['column_to_encode']

# Drop original categorical variable after it has been encoded
dataset_name = dataset_name.drop('categorical_column', axis = 1)

# join codings together
dataset_name = dataset_name.join([one_hot_column_name])

Hope this works, and welcome to Machine Learning!

