Cartesian product of columns of a DataFrame and setting newly created rows to 0 in Python

Viewed 282

Suppose, a DataFrame is in the form:

   column1  column2  is_duplicate
0   xyz      XYZ         1
1   xyz      XyZ         1
2   abc      ABC         1
3   abc      aBc         1

How to perform a Cartesian Product on column1 and column2 in such a way that newly created rows will have a value 0 while the original rows will still have 1 in is_duplicate column?

Expected DataFrame after output:

   column1  column2  is_duplicate
0   xyz      XYZ         1
1   xyz      XyZ         1
2   xyz      ABC         0
3   xyz      aBc         0
4   abc      XYZ         0
5   abc      XyZ         0
6   abc      ABC         1
7   abc      aBc         1
1 Answers
Related