Create 1/0 Dummy Variable in pandas DataFrame in Python (2 Examples) | get_dummies & concat Function

Published: 23 May 2022
on channel: Statistics Globe
800
13

How to convert a pandas DataFrame column to a 1/0 dummy matrix in the Python programming language. More details: https://statisticsglobe.com/create-du...
Python code of this video:

import pandas as pd # Import pandas library in Python

data = pd.DataFrame({'x1':range(10, 15), # Create example DataFrame
'x2':['x', 'y', 'y', 'x', 'y']})
print(data) # Print example DataFrame

data_dummies = pd.get_dummies(data['x2']) # Convert column to dummies
print(data_dummies) # Print dummies

data_all = pd.concat([data, data_dummies], # Combine original data & dummies
axis = 1)
print(data_all) # Print all data

Follow me on Social Media:
Facebook – Statistics Globe Page:   / statisticsglobecom  
Facebook – Group for Discussions & Questions:   / statisticsglobe  
LinkedIn – Statistics Globe Page:   / statisticsglobe  
LinkedIn – Group for Discussions & Questions:   / 12555223  
Twitter:   / joachimschork  

Music by bensound.com


On this page of the site you can watch the video online Create 1/0 Dummy Variable in pandas DataFrame in Python (2 Examples) | get_dummies & concat Function with a duration of hours minute second in good quality, which was uploaded by the user Statistics Globe 23 May 2022, share the link with friends and acquaintances, this video has already been watched 800 times on youtube and it was liked by 13 viewers. Enjoy your viewing!