I have DataFrame like below:
ABT = pd.read_excel("ABT.xlsx")
DATA TYPES:
COL1 - float
COL2 - int
COL3 - object
COL1 COL2 COL3 COL4 1.2 5 {"X":"cc", "y":12} {"A":{1,2}, "B":{3,3}"} 0.0 2 {"X":"dd", "y":13} {"A":{0,1}, "B":{2,2}"} 2.22 0 {"X":"ee", "y":45} {"A":{5,5}, "B":{1,1}"} ... ... ... ...
And I need to have something like below:
| COL1 | COL2| COL3 | X | y | A | B
|------|-----|--------------------|-----|-----|----------
| 1.2 | 5 | {"X":"cc", "y":12} | cc | 12 |
| 0.0 | 2 | {"X":"dd", "y":13} | dd | 13 |
| 2.22 | 0 | {"X":"ee", "y":45} | ee | 45 |
| ... | ... | ... | ... | ... |
I tried to use code like below, but it does not work:
pd.json_normalize(ABT)
because of error: AttributeError: 'str' object has no attribute 'values'
I also tried this one: pd.io.json.json_normalize(ABT.COL3[0])
but I have error: AttributeError: 'str' object has no attribute 'values'
How can I do that in Python Pandas ? I have a problem to image how should look output for values in COL4 ?
In my real DF:
When I use ABT.head().to_dict('list')
I have liek below:
{'COL1': [0.0],
'COL2': [2],
'COL3': [2162561990],
'COL4': [1500.0],
'COL5': [750.0],
'COL6': ['{"paAccounts": {"mySector": 4, "otherSectors": 10}}'],
'COL7': ['{"grade": "CC"}']}