I have a dataframe which looks like this after I split and expanded it using .str.split(' ', 40, expand=True)
to a whole physical address for each row.
0 1 2 3 4 5 flag
1255 N Camino AVE 1071 San Diego 1
1255 N DelSur AVE 1191 San Diego 1
3642 E CONSTITUTION DR San Diego CA 0
Now, I want to write a conditional function which overwrites column[4]. I want to say if flag==1 then replace column[4] values with whitespace else keep the value from column[4]. This is example the output should look like this:
0 1 2 3 4 5 flag
1255 N Camino AVE San Diego 1
1255 N DelSur AVE San Diego 1
3642 E CONSTITUTION DR San Diego CA 0
However, in my case, it spits out an error. Here is my code:
df[4] = ['' if i=='1' else addresses[4] for i in df['flag']]
**The output is an error: RecursionError: maximum recursion depth exceeded while calling a Python object**
Can someone help please?