本文介绍了字符串操作,然后将虚拟变量应用于它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在做一个小项目,以建立推荐系统.我有电影的类别列,我想在其上应用虚拟变量.
I am working on a small project to build a recommendation system. I have the movie's categories column and I would like to apply dummy variables on it.
#Here is my data
movie_data.head()
Customer MovieID Movie_title Movie_Category Movie_cost($)
C1 M1 Gladiator Drama,Action 3
C2 M2 The Accountant Drama,Crime 2
#Applying the dummy variables
df_dummies = pd.get_dummies(movie_data['Movie_Category'])
df_dummies.head()
#Here's the output:
Drama,Action Drama,Crime
1 0
0 1
#the desire output:
Drama Action Crime
1 1 0
1 0 1
推荐答案
df_dummies = movie_data['Movie_Category'].str.get_dummies(',')
这篇关于字符串操作,然后将虚拟变量应用于它们的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!