jeudi 28 mars 2019

how to get IF statement to work for looking up string in dataframe column [duplicate]

This question already has an answer here:

I only get "no" values written to my "eliminate" column when i know i should get some "yes"? df['Account Number'] is a dataframe column. I am looking for a string stored in variable "a".

Please help

import pandas as pd
a = user_input_links[1]
a = a.strip()

for i in df['Account Number']:
    if df['Account Number'].str.contains(a) is True:
        df['eliminate'] = "yes"
    else:
        df['eliminate'] = "no"


df.head()

Aucun commentaire:

Enregistrer un commentaire