1y = pd.get_dummies(df.Countries, prefix='Country')
2print(y.head())
3# from here you can merge it onto your main DF
1from sklearn.preprocessing import OneHotEncoder
2encoder = preprocessing.OneHotEncoder(handle_unknown='ignore')
3y = np.array([1, 2, 1, 3])
4y = y.reshape(-1,1)
5encoder.fit(y)
6y_oh = encoder.transform(y).toarray()
7print(y_oh)
8>>[[1. 0. 0.]
9 [0. 1. 0.]
10 [1. 0. 0.]
11 [0. 0. 1.]]