Skip to content

Instantly share code, notes, and snippets.

@ruoyu0088
Last active December 13, 2017 08:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ruoyu0088/4e775bf2b157fb14d547e3b1e4a24a22 to your computer and use it in GitHub Desktop.
Save ruoyu0088/4e775bf2b157fb14d547e3b1e4a24a22 to your computer and use it in GitHub Desktop.
import pandas as pd
import io
data = """ name, type, number
0, David, A, 1234
1, Tom, B, 2233
2, Jack, C, 2244
3, Allen, B, 2355
4, , D, 2345
5, Test, E, 3456
6, Test, A, 111
"""
df = pd.read_csv(io.StringIO(data), skipinitialspace=True)
df.name.fillna("", inplace=True)
types = ['A', 'B', 'C', 'D']
df.eval("is_valid = name != '' & type in @types & number >= 1000 & number <= 9999", inplace=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment