I am using Python 3 Pandas to do some data manipulation. I have one dataframe with a number of fields stored as columns (like layers in table 1) and I want to store those fields with different names in the dataframe under one column by row. In addition where more than one of these horizontal fields is not zero I want to duplicate the other columns. Basically as an example I want to go from table 1 too table 2
Normally if I were to do this in SQL I would Create the table 2, using only layer 1, renaming it to layer. Then append each subsequent layer. Then I would remove the non layer 1 fields with 0 in they're layer. But in Pandas I am unsure how to append columns with different names and from the same table. Also it would be good if I didn't need to do a separate append for each layer, if that's possible.