mercredi 21 décembre 2016

If statement using Pandas Python

I am trying to pass an "if statement" on an Excel file if certain characters exist in 2 different columns using pandas. There are no errors that occur when executing the code, but the code does not perform any of it's tasks. Here is the code I have so far:

def filter_getColumns2(y):
if r'[!|@|#|$|%|^|&|*]' in y['zonename']:
    y['zonename'] = y['zonename'].map(lambda x: re.sub(r'[!|@|#|$|%|&|*]', '', str(x)))
    return y
elif "  " in y['polygonstring']:
    for r, map in y.items():
        y['polygonstring'] = [re.sub(' +', ' ', e) for e in y['polygonstring']]
        y['polygonstring'] = [re.sub(' ,', ', ', e) for e in y['polygonstring']]
        y['polygonstring'] = y['polygonstring'].map(lambda x: x.lstrip(' '))
    return y
else:   
    return y

The code executes perfectly without the if statements, but I would just like to add the if statements to better the code. Thanks in advance, any thoughts or ideas is helpful!

-Mike

Aucun commentaire:

Enregistrer un commentaire