python - pandas: how to eliminate rows with value ending with a specific character? -


i have pandas dataframe follows:

mail = dataframe({'mail' : ['adv@gmail.com', 'fhngn@gmail.com', 'foinfo@yahoo.com', 'njfjrnfjrn@yahoo.com', 'nfjebfjen@hotmail.com', 'gnrgiprou@hotmail.com', 'jfei@hotmail.com']}) 

that looks like:

                    mail 0          adv@gmail.com 1        fhngn@gmail.com 2       foinfo@yahoo.com 3   njfjrnfjrn@yahoo.com 4  nfjebfjen@hotmail.com 5  gnrgiprou@hotmail.com 6       jfei@hotmail.com 

what want filter out (elimiante) rows in value in column mail ends '@gmail.com'.

you can use str.endswith , negate result of boolean series ~:

mail[~mail['mail'].str.endswith('@gmail.com')] 

which produces:

                    mail 2       foinfo@yahoo.com 3   njfjrnfjrn@yahoo.com 4  nfjebfjen@hotmail.com 5  gnrgiprou@hotmail.com 6       jfei@hotmail.com 

pandas has many other vectorised string operations accessible through .str accessor. many of these instantly familiar python's own string methods, come built in handling of nan values.


Comments

Popular posts from this blog

Process 'command 'F:\android-sdk\build-tools\21.1.2\aapt.exe'' finished with non-zero exit value 1 -

apache - setting document root in antoher partition on ubuntu -

java - Updating to mongo 3.0 -