I have a code which checks to see whether a column contains a list and if found it will explode that list and convert the exploded column into int
if it is numeric. However, I ran into a problem as some lists in my file contains dictionaries. How would I include that into my existing code to check whether the list contains a dictionary/keys, and if so, it should not explode that column and leave it as it is.
Current Code:
x = (doc.applymap(type) == list).all()
y = x.index[x].tolist()
for i in y:
doc= doc.explode(i)
if (doc[i].str.isnumeric().all()) == True:
x = (doc[i].to_frame().columns)
doc[x] = doc[x].fillna(0).astype(int)
Input:
ID
"number": [1,2,3,4],
"number": [{"enabled": 1,2,3,4}]
Expected Output
ID
1
2
3
4
[{"enabled": 1,2,3,4}]