字符串操作,然后将虚拟变量应用于它们 [英] String manipulation then applying dummy variables to them

查看:35
本文介绍了字符串操作,然后将虚拟变量应用于它们的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做一个小项目,以建立推荐系统.我有电影的类别列,我想在其上应用虚拟变量.

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

推荐答案

使用 查看全文

登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆