2

I have a pandas dataframe with rows created from dicts, using pd.io.json.json_normalize(). The values(not the keys/columns names) in dataframe have been modified. I want to retrieve a dict, with the same nested format the original dict has, from a row of the dataframe.

sample = {
    "A": {
        "a": 7        
    },

    "B": {
        "a": "name",
        "z":{
            "dD": 20 ,
            "f_f": 3 ,    
        }
    }
}

df = pd.io.json.json_normalize(sample, sep='__')

as expected df.columns returns me:

Index(['A__a', 'B__a', 'B__z__dD', 'B__z__f_f'], dtype='object')

I want to "reverse" the process now.

I can guarantee no string in the original dict(key or value) has a '__' as a substring and neither starts or ends with '_'

ojon
  • 323
  • 1
  • 3
  • 7
  • 1
    Possible duplicate of [Inverse of Pandas json\_normalize](https://stackoverflow.com/questions/54776916/inverse-of-pandas-json-normalize) – Abdul Niyas P M Jul 24 '19 at 14:12

0 Answers0