Skip to content
Advertisement

Is there a way to create columns from a list of phrases?

I have lists of phrases I would like to convert into columns in a dataframe to be used as inputs for a machine learning model. The code should find the unique phrases in all of the rows of data, create columns for the unique rows and indicate if the phrase is present in the row by showing a 1 if the phrase is present and a 0 if it is missing.

The phrases will look like the following:

JavaScript

Desired output in the dataframe:

enter image description here

Advertisement

Answer

First create the columns for the DataFrame:

JavaScript

Now to create the DataFrame rows:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement