'pandas creating new columns for each value in categorical columns

I have a pandas dataframe with some numeric and some categoric columns. I want to create a new column for each value of every categorical column and give that column a value of 1 in every row where that value is true and 0 in every row where that value is false. So the df is something like this -

col1          col2         col3
 A             P            1
 B             P            3
 A             Q            7

expected result is something like this:

col1          col2         col3      A        B       P        Q
 A             P            1        1        0       1        0
 B             P            3        0        1       1        0
 A             Q            7        1        0       0        1

Is this possible? can someone please help me?



Solution 1:[1]

You can use in your DAX query filter based on:

  'SomeTable'[CreateDate] >= DATE(YEAR(TODAY()),MONTH(TODAY())-8, 1)



EVALUATE
{TODAY(),
 DATE(YEAR(TODAY()),MONTH(TODAY())-8, 1),
 DATE(YEAR(TODAY()),MONTH(TODAY())-20, 1)
}

enter image description here

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 msta42a