I have a pandas dataframe as shown below.
DF1 =
sid path
1 '["rome","is","in","province","lazio"]'
1 "['rome', 'is', 'in', 'province', 'naples']"
1 ['N']
1 "['rome', 'is', 'in', 'province', 'in', 'campania']"
....
I want to remove all unnecessary characters of the column path so the result should look like this:
DF2 =
sid path
1 rome is in province lazio
1 rome is in province naples
1 N
1 rome is in province in campania
....
I tried replacing all the unnecessary characters like this :
DF1["path"].replace("[","").replace("]","").replace('"',"").replace(","," ").replace("'","")
But it didn't work. I suppose it's due to the entries ["N"]
How can I do this? Any help is appreciated!
['N']not quoted? Is it a list containing a string or is it supposed to be"['N']"?['N']is a list in this case.