СМОТРИ ТАКЖЕ
IIUC:
Вариант 1
Первое изменение 'hotel_cluster'
на категорию, включающую категории, которые неt существует
col = 'hotel_cluster'
df[col] = pd.Categorical(df[col], categories=[0, 1, 2, 3])
pd.crosstab(*map(df.get, df)).add_prefix(f"{col}_")
hotel_cluster hotel_cluster_0 hotel_cluster_1 hotel_cluster_2 hotel_cluster_3
User_id
1 1 0 0 0
2 0 0 1 0
3 1 0 1 1
4 0 0 1 0
Вариант 2
Переиндексация после crosstab
pd.crosstab(*map(df.get, df)).reindex(
columns=range(4), fill_value=0
).add_prefix('hotel_cluster_')
hotel_cluster hotel_cluster_0 hotel_cluster_1 hotel_cluster_2 hotel_cluster_3
User_id
1 1 0 0 0
2 0 0 1 0
3 1 0 1 1
4 0 0 1 0