I have a dataframe in which one columns values are lists of strings. here the structure of the file to read:
[
{
"key1":"value1 ",
"key2":"2",
"key3":["a","b 2 "," exp white space 210"],
},
{
"key1":"value1 ",
"key2":"2",
"key3":[],
},
]
I need to remove all white space for each item if it is more than one white space. expected output:
[
{
"key1":"value1",
"key2":"2",
"key3":["a","b2","exp white space 210"],
},
{
"key1":"value1",
"key2":"2",
"key3":[],
}
]
Note:
I have some value that are empty in some lines e.g "key3":[]
df.replace('\s+', ' ', regex=True)for multiple spaces and usestr.stripfor the leading and trailing spaces