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

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -