Let's say I have the following data frame:
"\n mark has \n no name",
"\n john walks his \n dog",
"mary is fun \n",
"tim is \n old"
data = [
"\n mark has \n no name",
"\n john walks his \n dog",
"mary is fun \n",
"tim is \n old"
]
df = pd.DataFrame(data, columns=['Sentences'])
How can I write a function, ideally a lambda, as I have not much practice with it, that will replace the first \n
and last \n
only in each of the above, so the output is:
"mark has \n no name",
"john walks his \n dog",
"mary is fun",
"tim is \n old"
Ideally, I would like the output to be a separate column on the data frame, as opposed to replacing what is there.
I have seen formulas that deal with a global replacement, but I need something a bit more specific.