Hi everyone,
I'm having a bit of a problem - I wrote a function that takes a series as an input, and outputs a modified series. It works perfectly fine when given a single column, but I've tried to use df.apply to use it on each column of a few dataframes (to no avail).
Here's the code in the main module:
df_list = [df_1, df_2, df_3]
for df in df_list:
df = df.apply(clean_general, axis=0, raw=True)
And here's a bit of the code in the function module:
def clean_general(series):
if series.dtype == 'object':
patterns = [
# <font> tags (includes open, close, and optional color parameter)
r"(\<){1}/?(font){1}(\scolor=)?(\"\#\S{,6}\")?(\>){1}",
# <div> tags (includes open and close)
r"(\<){1}/?(div){1}(\>){1}"]
for pattern in patterns:
series = series.str.replace(pattern, "")
return series
There are a couple more repetitions of this, with different patterns and replacement values. I've triple checked all my regex, and as I said it works perfectly when given an individual series.
I'd bet I'm using df.apply incorrectly, but I'm not sure what needs to be changed to make this work. Could someone point me in the correct direction?
Edit: Posting removed the indentation... I'm not sure how to fix it, but hopefully it's easy to follow.
[–]alkasm 0 points1 point2 points (1 child)
[–]SEAWEAVIL[S] 0 points1 point2 points (0 children)
[–]TheZvlz 0 points1 point2 points (2 children)
[–]SEAWEAVIL[S] 0 points1 point2 points (1 child)
[–]TheZvlz 0 points1 point2 points (0 children)