Creating new columns based on value from another column in pandas
问题 I have this pandas dataframe with column "Code" that contains the sequential hierarchical code. My goal is to create new columns with each hierarchical level code and its name as followed: Original data: Code Name 0 A USA 1 AM Massachusetts 2 AMB Boston 3 AMS Springfield 4 D Germany 5 DB Brandenburg 6 DBB Berlin 7 DBD Dresden My Goal: Code Name Level1 Level1Name Level2 Level2Name Level3 Level3Name 0 A USA A USA AM Massachusetts AMB Boston 1 AM Massachusetts A USA AM Massachusetts AMB Boston 2