I have a dataframe like this,
df
col1 col2 col3
1907 CD 49
1907 FR 33
1907 SA 34
1908 PR 1
1908 SA 37
1909 PR 16
1909 SA 38
Now CD is not present with col1 1908 and 1909 values, FR not present with 1908 and 1909 values and PR not present wth 1907.
Now I want to create rows with col2 values which are not with all col1 values with col3 values as 0.
So final dataframe will look like,
df
col1 col2 col3
1907 CD 49
1907 FR 33
1907 SA 34
1907 PR 0
1908 CD 0
1908 FR 0
1908 PR 1
1908 SA 37
1908 CD 0
1908 FR 0
1909 PR 16
1909 SA 38
I could do this using a for loop with every possible col2 values and comparing with every col1 group. But I am looking for shortcuts to do it most efficiently.