How to Create Dummy Variable in Python
This tutorial shows two methods of creating dummy variables in Python. The following shows the key syntax. Method 1: Use Numpy.where() to create a dummy variable np.where(df[‘column_of_interest’] == ‘value’ ,1,0) Method 2: Use apply() and lambda function to create a dummy variable df[‘column_of_interest’].apply(lambda x: 1 if x==’value’ else 0) Example 1: Use numpy.where() to create … Read more