I understand that pandas is designed to load completely filled dataframes, but I want to add single rows to to the data frame under specific condition. Following is the df I am dealing with
ProjID Xcoord Ycoord
0 2 some_val some_val
1 2 some_val some_val
2 2 some_val some_val
3 2 some_val some_val
4 2 some_val some_val
5 3 some_val some_val
6 3 some_val some_val
7 5 some_val some_val
8 5 some_val some_val
9 5 some_val some_val
What I want is to insert a row in the df with value 0 for every column, whenever the ProjID changes. Below is the required df:
ProjID Xcoord Ycoord
0 2 some_val some_val
1 2 some_val some_val
2 2 some_val some_val
3 2 some_val some_val
4 2 some_val some_val
5 0 0 0
6 3 some_val some_val
7 3 some_val some_val
8 0 0 0
9 5 some_val some_val
10 5 some_val some_val
11 5 some_val some_val
12 0 0 0
Basically a row with 0 values is inserted everytime, the ProjID changes. I was trying to write a for loop where the values in ProjID col is checked with previous row value of the ProjID col, if they are same, then it will move ahead, if they are not same, then it should insert a row with all 0 values. But, I am unable to implement it. Also, I have no idea how the index column will behave.
Please let me know if this kind of insertion of a row is possible in a df, and how do I do it. Thanks for any help.