You're looking for
df['Title'].str.replace('\n', '')
Also remember that this replacement doesn't happen in-place. To change the original dataframe, you're going to have to do
df['Title'] = df['Title'].str.replace('\n', '')
df.str
provides vectorized string functions to operate on each value in the column. df.str.replace('\n', '')
runs the str.replace()
function on each element of df
.
df.replace()
replaces entire values in the column with the given replacement.
For example,
data = [{"x": "hello\n"}, {"x": "yello\n"}, {"x": "jello\n"}]
df = pd.DataFrame(data)
# df:
# x
# 0 hello\n
# 1 yello\n
# 2 jello\n
df["x"].str.replace('\n', '')
# df["x"]:
# 0 hello
# 1 yello
# 2 jello
df["x"].replace('yello\n', 'bello\n')
# df["x"]:
# 0 hello\n
# 1 bello\n
# 2 jello\n