jeudi 24 octobre 2019

looping though values based on a condition

I am trying to create a function in python that checks if the data in the dataframe is following a certain structure in my case i need to ensure that the id column is structured like this ID0101-10

here is my code but it is not working, i keep getting an indexing error:

i = 0 
for i in df["id"]:
    if ('-' in df["id"]):
        df["id"].iloc[i] = df["id"].iloc[i]
        i += 1
    else:
        df.drop(df["id"].iloc[i])
        i += 1

if you're curious about my data, its like this: id name ID0101-10 John
ID0101-11 Mary 8454 Test MMMM MMMM ID0101-01 Ben MN87876 00.00

i am trying to clean my data by dropping the dummy values

Any help is appreciated thanks

Aucun commentaire:

Enregistrer un commentaire