In [1]:
import pandas as pd
In [17]:
# Cast to Datetime - ver 1
df = pd.read_csv('data/employees.csv')
df['Start Date'] = pd.to_datetime(df['Start Date'])
df['Last Login Time'] = pd.to_datetime(df['Last Login Time'])
df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 1000 entries, 0 to 999
Data columns (total 8 columns):
First Name 933 non-null object
Gender 855 non-null object
Start Date 1000 non-null datetime64[ns]
Last Login Time 1000 non-null datetime64[ns]
Salary 1000 non-null int64
Bonus % 1000 non-null float64
Senior Management 933 non-null object
Team 957 non-null object
dtypes: datetime64[ns](2), float64(1), int64(1), object(4)
memory usage: 62.6+ KB
In [18]:
# Cast to Datetime - ver 2
df = pd.read_csv('data/employees.csv', parse_dates=['Start Date', 'Last Login Time'])
df.head()
Out[18]:
First Name
Gender
Start Date
Last Login Time
Salary
Bonus %
Senior Management
Team
0
Douglas
Male
1993-08-06
2017-05-17 12:42:00
97308
6.945
True
Marketing
1
Thomas
Male
1996-03-31
2017-05-17 06:53:00
61933
4.170
True
NaN
2
Maria
Female
1993-04-23
2017-05-17 11:17:00
130590
11.858
False
Finance
3
Jerry
Male
2005-03-04
2017-05-17 13:00:00
138705
9.340
True
Finance
4
Larry
Male
1998-01-24
2017-05-17 16:47:00
101004
1.389
True
Client Services
In [6]:
df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 1000 entries, 0 to 999
Data columns (total 8 columns):
First Name 933 non-null object
Gender 855 non-null object
Start Date 1000 non-null datetime64[ns]
Last Login Time 1000 non-null datetime64[ns]
Salary 1000 non-null int64
Bonus % 1000 non-null float64
Senior Management 933 non-null object
Team 957 non-null object
dtypes: datetime64[ns](2), float64(1), int64(1), object(4)
memory usage: 62.6+ KB
In [29]:
df['Gender'].nunique()
df['Senior Management'].nunique()
df['Team'].nunique()
Out[29]:
10
In [30]:
df['Gender'] = df['Gender'].astype('category')
df['Team'] = df['Team'].astype('category')
df['Senior Management'] = df['Senior Management'].astype('bool')
In [31]:
df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 1000 entries, 0 to 999
Data columns (total 8 columns):
First Name 933 non-null object
Gender 855 non-null category
Start Date 1000 non-null datetime64[ns]
Last Login Time 1000 non-null datetime64[ns]
Salary 1000 non-null int64
Bonus % 1000 non-null float64
Senior Management 1000 non-null bool
Team 957 non-null category
dtypes: bool(1), category(2), datetime64[ns](2), float64(1), int64(1), object(1)
memory usage: 42.5+ KB
In [41]:
df = pd.read_csv('data/employees.csv', parse_dates=['Start Date', 'Last Login Time'])
df['Gender'] = df['Gender'].astype('category')
df['Team'] = df['Team'].astype('category')
df['Senior Management'] = df['Senior Management'].astype('bool')
df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 1000 entries, 0 to 999
Data columns (total 8 columns):
First Name 933 non-null object
Gender 855 non-null category
Start Date 1000 non-null datetime64[ns]
Last Login Time 1000 non-null datetime64[ns]
Salary 1000 non-null int64
Bonus % 1000 non-null float64
Senior Management 1000 non-null bool
Team 957 non-null category
dtypes: bool(1), category(2), datetime64[ns](2), float64(1), int64(1), object(1)
memory usage: 42.5+ KB
In [42]:
is_male = df['Gender'] == 'Male'
df.insert(2, column='is_male', value=is_male)
In [43]:
df.info()
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 1000 entries, 0 to 999
Data columns (total 9 columns):
First Name 933 non-null object
Gender 855 non-null category
is_male 1000 non-null bool
Start Date 1000 non-null datetime64[ns]
Last Login Time 1000 non-null datetime64[ns]
Salary 1000 non-null int64
Bonus % 1000 non-null float64
Senior Management 1000 non-null bool
Team 957 non-null category
dtypes: bool(2), category(2), datetime64[ns](2), float64(1), int64(1), object(1)
memory usage: 43.5+ KB
In [44]:
df.head()
Out[44]:
First Name
Gender
is_male
Start Date
Last Login Time
Salary
Bonus %
Senior Management
Team
0
Douglas
Male
True
1993-08-06
2017-05-17 12:42:00
97308
6.945
True
Marketing
1
Thomas
Male
True
1996-03-31
2017-05-17 06:53:00
61933
4.170
True
NaN
2
Maria
Female
False
1993-04-23
2017-05-17 11:17:00
130590
11.858
False
Finance
3
Jerry
Male
True
2005-03-04
2017-05-17 13:00:00
138705
9.340
True
Finance
4
Larry
Male
True
1998-01-24
2017-05-17 16:47:00
101004
1.389
True
Client Services
In [45]:
df[df['is_male']==True]
Out[45]:
First Name
Gender
is_male
Start Date
Last Login Time
Salary
Bonus %
Senior Management
Team
0
Douglas
Male
True
1993-08-06
2017-05-17 12:42:00
97308
6.945
True
Marketing
1
Thomas
Male
True
1996-03-31
2017-05-17 06:53:00
61933
4.170
True
NaN
3
Jerry
Male
True
2005-03-04
2017-05-17 13:00:00
138705
9.340
True
Finance
4
Larry
Male
True
1998-01-24
2017-05-17 16:47:00
101004
1.389
True
Client Services
5
Dennis
Male
True
1987-04-18
2017-05-17 01:35:00
115163
10.125
False
Legal
12
Brandon
Male
True
1980-12-01
2017-05-17 01:08:00
112807
17.492
True
Human Resources
13
Gary
Male
True
2008-01-27
2017-05-17 23:40:00
109831
5.831
False
Sales
16
Jeremy
Male
True
2010-09-21
2017-05-17 05:56:00
90370
7.369
False
Human Resources
17
Shawn
Male
True
1986-12-07
2017-05-17 19:45:00
111737
6.414
False
Product
21
Matthew
Male
True
1995-09-05
2017-05-17 02:12:00
100612
13.645
False
Marketing
23
NaN
Male
True
2012-06-14
2017-05-17 16:19:00
125792
5.042
True
NaN
24
John
Male
True
1992-07-01
2017-05-17 22:08:00
97950
13.873
False
Client Services
25
NaN
Male
True
2012-10-08
2017-05-17 01:12:00
37076
18.576
True
Client Services
26
Craig
Male
True
2000-02-27
2017-05-17 07:45:00
37598
7.757
True
Marketing
28
Terry
Male
True
1981-11-27
2017-05-17 18:30:00
124008
13.464
True
Client Services
29
Benjamin
Male
True
2005-01-26
2017-05-17 22:06:00
79529
7.008
True
Legal
32
NaN
Male
True
1998-08-21
2017-05-17 14:27:00
122340
6.417
True
NaN
34
Jerry
Male
True
2004-01-10
2017-05-17 12:56:00
95734
19.096
False
Client Services
39
NaN
Male
True
2016-01-29
2017-05-17 02:33:00
122173
7.797
True
Client Services
40
Michael
Male
True
2008-10-10
2017-05-17 11:25:00
99283
2.665
True
Distribution
45
Roger
Male
True
1980-04-17
2017-05-17 11:32:00
88010
13.886
True
Sales
46
Bruce
Male
True
2009-11-28
2017-05-17 22:47:00
114796
6.796
False
Finance
48
Clarence
Male
True
1996-03-26
2017-05-17 05:57:00
93581
6.083
True
Business Development
52
Todd
Male
True
1990-02-18
2017-05-17 02:41:00
49339
1.695
True
Human Resources
56
Carl
Male
True
2006-05-03
2017-05-17 17:55:00
130276
16.084
True
Finance
57
Henry
Male
True
1996-06-26
2017-05-17 01:44:00
64715
15.107
True
Human Resources
63
Matthew
Male
True
2013-01-02
2017-05-17 22:33:00
35203
18.040
False
Human Resources
65
Steve
Male
True
2009-11-11
2017-05-17 23:44:00
61310
12.428
True
Distribution
68
Jose
Male
True
2004-10-30
2017-05-17 13:39:00
84834
14.330
True
Finance
71
Johnny
Male
True
2009-11-06
2017-05-17 16:23:00
118172
16.194
True
Sales
...
...
...
...
...
...
...
...
...
...
931
Harold
Male
True
2012-06-23
2017-05-17 12:40:00
140444
3.771
False
Distribution
934
Samuel
Male
True
1997-08-07
2017-05-17 12:40:00
43694
3.787
True
Engineering
940
Andrew
Male
True
1990-09-28
2017-05-17 09:38:00
137386
8.611
True
Distribution
941
William
Male
True
1997-06-26
2017-05-17 08:33:00
104840
15.653
True
Engineering
943
Wayne
Male
True
2006-09-08
2017-05-17 11:09:00
67471
2.728
False
Engineering
944
Kenneth
Male
True
2006-05-10
2017-05-17 08:24:00
101914
1.905
True
Distribution
947
NaN
Male
True
2012-07-30
2017-05-17 15:07:00
107351
5.329
True
Marketing
949
Scott
Male
True
2011-08-20
2017-05-17 08:08:00
37385
8.226
True
Business Development
953
Randy
Male
True
2012-02-25
2017-05-17 05:33:00
57266
14.077
False
Product
954
Joe
Male
True
1980-01-19
2017-05-17 16:06:00
119667
1.148
True
Finance
957
Jeffrey
Male
True
1984-02-03
2017-05-17 13:26:00
70990
15.901
True
Sales
959
Albert
Male
True
1992-09-19
2017-05-17 02:35:00
45094
5.850
True
Business Development
960
Stephen
Male
True
1989-10-29
2017-05-17 23:34:00
93997
18.093
True
Business Development
962
Jonathan
Male
True
2013-08-21
2017-05-17 00:45:00
121797
16.923
False
Product
964
Bruce
Male
True
1980-05-07
2017-05-17 20:00:00
35802
12.391
True
Sales
966
Louis
Male
True
2011-08-16
2017-05-17 17:19:00
93022
9.146
True
Human Resources
967
Thomas
Male
True
2016-03-12
2017-05-17 15:10:00
105681
19.572
False
Engineering
971
Patrick
Male
True
2002-12-30
2017-05-17 02:01:00
75423
5.368
True
Business Development
973
Russell
Male
True
2013-05-10
2017-05-17 23:08:00
137359
11.105
False
Business Development
974
Harry
Male
True
2011-08-30
2017-05-17 18:31:00
67656
16.455
True
Client Services
978
Sean
Male
True
1983-01-17
2017-05-17 14:23:00
66146
11.178
False
Human Resources
979
Ernest
Male
True
2013-07-20
2017-05-17 06:41:00
142935
13.198
True
Product
981
James
Male
True
1993-01-15
2017-05-17 17:19:00
148985
19.280
False
Legal
983
John
Male
True
1982-12-23
2017-05-17 22:35:00
146907
11.738
False
Engineering
992
Anthony
Male
True
2011-10-16
2017-05-17 08:35:00
112769
11.625
True
Finance
994
George
Male
True
2013-06-21
2017-05-17 17:47:00
98874
4.479
True
Marketing
996
Phillip
Male
True
1984-01-31
2017-05-17 06:30:00
42392
19.675
False
Finance
997
Russell
Male
True
2013-05-20
2017-05-17 12:39:00
96914
1.421
False
Product
998
Larry
Male
True
2013-04-20
2017-05-17 16:45:00
60500
11.985
False
Business Development
999
Albert
Male
True
2012-05-15
2017-05-17 18:24:00
129949
10.169
True
Sales
424 rows × 9 columns
In [46]:
df[df['Gender']=='Male']
Out[46]:
First Name
Gender
is_male
Start Date
Last Login Time
Salary
Bonus %
Senior Management
Team
0
Douglas
Male
True
1993-08-06
2017-05-17 12:42:00
97308
6.945
True
Marketing
1
Thomas
Male
True
1996-03-31
2017-05-17 06:53:00
61933
4.170
True
NaN
3
Jerry
Male
True
2005-03-04
2017-05-17 13:00:00
138705
9.340
True
Finance
4
Larry
Male
True
1998-01-24
2017-05-17 16:47:00
101004
1.389
True
Client Services
5
Dennis
Male
True
1987-04-18
2017-05-17 01:35:00
115163
10.125
False
Legal
12
Brandon
Male
True
1980-12-01
2017-05-17 01:08:00
112807
17.492
True
Human Resources
13
Gary
Male
True
2008-01-27
2017-05-17 23:40:00
109831
5.831
False
Sales
16
Jeremy
Male
True
2010-09-21
2017-05-17 05:56:00
90370
7.369
False
Human Resources
17
Shawn
Male
True
1986-12-07
2017-05-17 19:45:00
111737
6.414
False
Product
21
Matthew
Male
True
1995-09-05
2017-05-17 02:12:00
100612
13.645
False
Marketing
23
NaN
Male
True
2012-06-14
2017-05-17 16:19:00
125792
5.042
True
NaN
24
John
Male
True
1992-07-01
2017-05-17 22:08:00
97950
13.873
False
Client Services
25
NaN
Male
True
2012-10-08
2017-05-17 01:12:00
37076
18.576
True
Client Services
26
Craig
Male
True
2000-02-27
2017-05-17 07:45:00
37598
7.757
True
Marketing
28
Terry
Male
True
1981-11-27
2017-05-17 18:30:00
124008
13.464
True
Client Services
29
Benjamin
Male
True
2005-01-26
2017-05-17 22:06:00
79529
7.008
True
Legal
32
NaN
Male
True
1998-08-21
2017-05-17 14:27:00
122340
6.417
True
NaN
34
Jerry
Male
True
2004-01-10
2017-05-17 12:56:00
95734
19.096
False
Client Services
39
NaN
Male
True
2016-01-29
2017-05-17 02:33:00
122173
7.797
True
Client Services
40
Michael
Male
True
2008-10-10
2017-05-17 11:25:00
99283
2.665
True
Distribution
45
Roger
Male
True
1980-04-17
2017-05-17 11:32:00
88010
13.886
True
Sales
46
Bruce
Male
True
2009-11-28
2017-05-17 22:47:00
114796
6.796
False
Finance
48
Clarence
Male
True
1996-03-26
2017-05-17 05:57:00
93581
6.083
True
Business Development
52
Todd
Male
True
1990-02-18
2017-05-17 02:41:00
49339
1.695
True
Human Resources
56
Carl
Male
True
2006-05-03
2017-05-17 17:55:00
130276
16.084
True
Finance
57
Henry
Male
True
1996-06-26
2017-05-17 01:44:00
64715
15.107
True
Human Resources
63
Matthew
Male
True
2013-01-02
2017-05-17 22:33:00
35203
18.040
False
Human Resources
65
Steve
Male
True
2009-11-11
2017-05-17 23:44:00
61310
12.428
True
Distribution
68
Jose
Male
True
2004-10-30
2017-05-17 13:39:00
84834
14.330
True
Finance
71
Johnny
Male
True
2009-11-06
2017-05-17 16:23:00
118172
16.194
True
Sales
...
...
...
...
...
...
...
...
...
...
931
Harold
Male
True
2012-06-23
2017-05-17 12:40:00
140444
3.771
False
Distribution
934
Samuel
Male
True
1997-08-07
2017-05-17 12:40:00
43694
3.787
True
Engineering
940
Andrew
Male
True
1990-09-28
2017-05-17 09:38:00
137386
8.611
True
Distribution
941
William
Male
True
1997-06-26
2017-05-17 08:33:00
104840
15.653
True
Engineering
943
Wayne
Male
True
2006-09-08
2017-05-17 11:09:00
67471
2.728
False
Engineering
944
Kenneth
Male
True
2006-05-10
2017-05-17 08:24:00
101914
1.905
True
Distribution
947
NaN
Male
True
2012-07-30
2017-05-17 15:07:00
107351
5.329
True
Marketing
949
Scott
Male
True
2011-08-20
2017-05-17 08:08:00
37385
8.226
True
Business Development
953
Randy
Male
True
2012-02-25
2017-05-17 05:33:00
57266
14.077
False
Product
954
Joe
Male
True
1980-01-19
2017-05-17 16:06:00
119667
1.148
True
Finance
957
Jeffrey
Male
True
1984-02-03
2017-05-17 13:26:00
70990
15.901
True
Sales
959
Albert
Male
True
1992-09-19
2017-05-17 02:35:00
45094
5.850
True
Business Development
960
Stephen
Male
True
1989-10-29
2017-05-17 23:34:00
93997
18.093
True
Business Development
962
Jonathan
Male
True
2013-08-21
2017-05-17 00:45:00
121797
16.923
False
Product
964
Bruce
Male
True
1980-05-07
2017-05-17 20:00:00
35802
12.391
True
Sales
966
Louis
Male
True
2011-08-16
2017-05-17 17:19:00
93022
9.146
True
Human Resources
967
Thomas
Male
True
2016-03-12
2017-05-17 15:10:00
105681
19.572
False
Engineering
971
Patrick
Male
True
2002-12-30
2017-05-17 02:01:00
75423
5.368
True
Business Development
973
Russell
Male
True
2013-05-10
2017-05-17 23:08:00
137359
11.105
False
Business Development
974
Harry
Male
True
2011-08-30
2017-05-17 18:31:00
67656
16.455
True
Client Services
978
Sean
Male
True
1983-01-17
2017-05-17 14:23:00
66146
11.178
False
Human Resources
979
Ernest
Male
True
2013-07-20
2017-05-17 06:41:00
142935
13.198
True
Product
981
James
Male
True
1993-01-15
2017-05-17 17:19:00
148985
19.280
False
Legal
983
John
Male
True
1982-12-23
2017-05-17 22:35:00
146907
11.738
False
Engineering
992
Anthony
Male
True
2011-10-16
2017-05-17 08:35:00
112769
11.625
True
Finance
994
George
Male
True
2013-06-21
2017-05-17 17:47:00
98874
4.479
True
Marketing
996
Phillip
Male
True
1984-01-31
2017-05-17 06:30:00
42392
19.675
False
Finance
997
Russell
Male
True
2013-05-20
2017-05-17 12:39:00
96914
1.421
False
Product
998
Larry
Male
True
2013-04-20
2017-05-17 16:45:00
60500
11.985
False
Business Development
999
Albert
Male
True
2012-05-15
2017-05-17 18:24:00
129949
10.169
True
Sales
424 rows × 9 columns
In [47]:
df[df['Team'] == 'Finance'] # equal to Finance
Out[47]:
First Name
Gender
is_male
Start Date
Last Login Time
Salary
Bonus %
Senior Management
Team
2
Maria
Female
False
1993-04-23
2017-05-17 11:17:00
130590
11.858
False
Finance
3
Jerry
Male
True
2005-03-04
2017-05-17 13:00:00
138705
9.340
True
Finance
7
NaN
Female
False
2015-07-20
2017-05-17 10:43:00
45906
11.598
True
Finance
14
Kimberly
Female
False
1999-01-14
2017-05-17 07:13:00
41426
14.543
True
Finance
46
Bruce
Male
True
2009-11-28
2017-05-17 22:47:00
114796
6.796
False
Finance
53
Alan
NaN
False
2014-03-03
2017-05-17 13:28:00
40341
17.578
True
Finance
56
Carl
Male
True
2006-05-03
2017-05-17 17:55:00
130276
16.084
True
Finance
67
Rachel
Female
False
1999-08-16
2017-05-17 06:53:00
51178
9.735
True
Finance
68
Jose
Male
True
2004-10-30
2017-05-17 13:39:00
84834
14.330
True
Finance
69
Irene
NaN
False
2015-07-14
2017-05-17 16:31:00
100863
4.382
True
Finance
83
Shawn
Male
True
2005-09-23
2017-05-17 02:55:00
148115
6.539
True
Finance
84
Doris
Female
False
2004-08-20
2017-05-17 05:51:00
83072
7.511
False
Finance
96
Cynthia
Female
False
1994-03-21
2017-05-17 08:34:00
142321
1.737
False
Finance
100
Melissa
Female
False
2005-06-21
2017-05-17 06:33:00
48109
14.995
False
Finance
103
Phyllis
Female
False
1996-10-11
2017-05-17 21:30:00
136984
8.932
True
Finance
105
Kathy
Female
False
1996-03-09
2017-05-17 04:33:00
91712
8.567
False
Finance
117
Steven
Male
True
1995-03-01
2017-05-17 15:03:00
109095
9.494
False
Finance
142
Elizabeth
Female
False
2003-10-09
2017-05-17 17:53:00
146129
5.687
False
Finance
153
Victor
NaN
False
2011-03-10
2017-05-17 20:40:00
84546
10.489
True
Finance
160
Kathy
Female
False
2000-03-18
2017-05-17 19:26:00
149563
16.991
True
Finance
172
Sara
Female
False
1991-09-23
2017-05-17 18:17:00
97058
9.402
False
Finance
179
Jessica
Female
False
1995-10-23
2017-05-17 05:53:00
68759
19.343
True
Finance
190
Carol
Female
False
1996-03-19
2017-05-17 03:39:00
57783
9.129
False
Finance
200
Gary
Male
True
1987-08-12
2017-05-17 00:04:00
89661
8.525
False
Finance
205
Brandon
Male
True
2006-03-27
2017-05-17 17:54:00
115711
8.012
True
Finance
218
Gregory
NaN
False
1992-06-15
2017-05-17 05:08:00
98865
10.628
True
Finance
219
Billy
Male
True
1995-03-13
2017-05-17 12:05:00
120444
7.768
True
Finance
222
Jason
Male
True
1999-10-17
2017-05-17 22:09:00
78417
3.067
False
Finance
226
Kathy
Female
False
1995-04-19
2017-05-17 00:46:00
50905
9.404
True
Finance
241
Walter
Male
True
1983-07-06
2017-05-17 23:54:00
127813
5.961
False
Finance
...
...
...
...
...
...
...
...
...
...
710
Edward
Male
True
1997-11-27
2017-05-17 01:00:00
58327
17.095
True
Finance
725
Jeremy
Male
True
1991-05-19
2017-05-17 13:40:00
131513
1.876
True
Finance
731
Ann
Female
False
2001-07-16
2017-05-17 09:27:00
118431
12.772
True
Finance
732
Henry
Male
True
1986-05-12
2017-05-17 02:04:00
59943
1.432
False
Finance
744
Judy
NaN
False
2011-07-15
2017-05-17 15:38:00
46829
5.190
True
Finance
765
Alice
NaN
False
1995-04-23
2017-05-17 06:35:00
148339
11.479
True
Finance
773
NaN
Male
True
1986-10-24
2017-05-17 09:23:00
47176
10.736
True
Finance
775
Rose
Female
False
1999-11-03
2017-05-17 09:06:00
75181
6.060
True
Finance
790
Fred
Male
True
1989-03-03
2017-05-17 02:27:00
129712
11.058
False
Finance
807
Mary
Female
False
2011-11-06
2017-05-17 08:32:00
115057
2.089
False
Finance
809
George
Male
True
1995-09-27
2017-05-17 17:04:00
36749
19.754
False
Finance
831
Kenneth
Male
True
2015-01-15
2017-05-17 14:41:00
69112
7.588
True
Finance
836
Carolyn
Female
False
2004-03-17
2017-05-17 06:38:00
118037
13.492
False
Finance
837
Joseph
Male
True
1985-05-23
2017-05-17 22:16:00
139570
15.804
True
Finance
847
Nicole
NaN
False
1981-05-02
2017-05-17 12:03:00
41449
4.707
False
Finance
854
Harry
Male
True
1985-02-10
2017-05-17 19:46:00
63046
10.411
False
Finance
856
Bonnie
NaN
False
2006-01-18
2017-05-17 18:52:00
108946
12.211
False
Finance
861
Jerry
Male
True
1989-03-26
2017-05-17 04:15:00
140850
18.855
False
Finance
880
Robert
NaN
False
2007-05-25
2017-05-17 03:17:00
90998
8.382
False
Finance
884
Lisa
Female
False
2003-10-17
2017-05-17 13:42:00
73706
18.530
False
Finance
889
Margaret
Female
False
2001-01-04
2017-05-17 03:07:00
126924
1.552
True
Finance
890
NaN
Male
True
2015-11-24
2017-05-17 03:11:00
145329
7.100
True
Finance
891
Timothy
Male
True
1991-08-25
2017-05-17 10:37:00
92587
8.475
False
Finance
897
Kenneth
NaN
False
1994-02-28
2017-05-17 10:10:00
95296
10.146
False
Finance
905
Alice
Female
False
2013-02-09
2017-05-17 00:49:00
121250
4.363
True
Finance
907
Elizabeth
Female
False
1998-07-27
2017-05-17 11:12:00
137144
10.081
False
Finance
954
Joe
Male
True
1980-01-19
2017-05-17 16:06:00
119667
1.148
True
Finance
987
Gloria
Female
False
2014-12-08
2017-05-17 05:08:00
136709
10.331
True
Finance
992
Anthony
Male
True
2011-10-16
2017-05-17 08:35:00
112769
11.625
True
Finance
996
Phillip
Male
True
1984-01-31
2017-05-17 06:30:00
42392
19.675
False
Finance
102 rows × 9 columns
In [50]:
mask = df['Team'] == 'Finance'
In [51]:
df[mask]
Out[51]:
First Name
Gender
is_male
Start Date
Last Login Time
Salary
Bonus %
Senior Management
Team
2
Maria
Female
False
1993-04-23
2017-05-17 11:17:00
130590
11.858
False
Finance
3
Jerry
Male
True
2005-03-04
2017-05-17 13:00:00
138705
9.340
True
Finance
7
NaN
Female
False
2015-07-20
2017-05-17 10:43:00
45906
11.598
True
Finance
14
Kimberly
Female
False
1999-01-14
2017-05-17 07:13:00
41426
14.543
True
Finance
46
Bruce
Male
True
2009-11-28
2017-05-17 22:47:00
114796
6.796
False
Finance
53
Alan
NaN
False
2014-03-03
2017-05-17 13:28:00
40341
17.578
True
Finance
56
Carl
Male
True
2006-05-03
2017-05-17 17:55:00
130276
16.084
True
Finance
67
Rachel
Female
False
1999-08-16
2017-05-17 06:53:00
51178
9.735
True
Finance
68
Jose
Male
True
2004-10-30
2017-05-17 13:39:00
84834
14.330
True
Finance
69
Irene
NaN
False
2015-07-14
2017-05-17 16:31:00
100863
4.382
True
Finance
83
Shawn
Male
True
2005-09-23
2017-05-17 02:55:00
148115
6.539
True
Finance
84
Doris
Female
False
2004-08-20
2017-05-17 05:51:00
83072
7.511
False
Finance
96
Cynthia
Female
False
1994-03-21
2017-05-17 08:34:00
142321
1.737
False
Finance
100
Melissa
Female
False
2005-06-21
2017-05-17 06:33:00
48109
14.995
False
Finance
103
Phyllis
Female
False
1996-10-11
2017-05-17 21:30:00
136984
8.932
True
Finance
105
Kathy
Female
False
1996-03-09
2017-05-17 04:33:00
91712
8.567
False
Finance
117
Steven
Male
True
1995-03-01
2017-05-17 15:03:00
109095
9.494
False
Finance
142
Elizabeth
Female
False
2003-10-09
2017-05-17 17:53:00
146129
5.687
False
Finance
153
Victor
NaN
False
2011-03-10
2017-05-17 20:40:00
84546
10.489
True
Finance
160
Kathy
Female
False
2000-03-18
2017-05-17 19:26:00
149563
16.991
True
Finance
172
Sara
Female
False
1991-09-23
2017-05-17 18:17:00
97058
9.402
False
Finance
179
Jessica
Female
False
1995-10-23
2017-05-17 05:53:00
68759
19.343
True
Finance
190
Carol
Female
False
1996-03-19
2017-05-17 03:39:00
57783
9.129
False
Finance
200
Gary
Male
True
1987-08-12
2017-05-17 00:04:00
89661
8.525
False
Finance
205
Brandon
Male
True
2006-03-27
2017-05-17 17:54:00
115711
8.012
True
Finance
218
Gregory
NaN
False
1992-06-15
2017-05-17 05:08:00
98865
10.628
True
Finance
219
Billy
Male
True
1995-03-13
2017-05-17 12:05:00
120444
7.768
True
Finance
222
Jason
Male
True
1999-10-17
2017-05-17 22:09:00
78417
3.067
False
Finance
226
Kathy
Female
False
1995-04-19
2017-05-17 00:46:00
50905
9.404
True
Finance
241
Walter
Male
True
1983-07-06
2017-05-17 23:54:00
127813
5.961
False
Finance
...
...
...
...
...
...
...
...
...
...
710
Edward
Male
True
1997-11-27
2017-05-17 01:00:00
58327
17.095
True
Finance
725
Jeremy
Male
True
1991-05-19
2017-05-17 13:40:00
131513
1.876
True
Finance
731
Ann
Female
False
2001-07-16
2017-05-17 09:27:00
118431
12.772
True
Finance
732
Henry
Male
True
1986-05-12
2017-05-17 02:04:00
59943
1.432
False
Finance
744
Judy
NaN
False
2011-07-15
2017-05-17 15:38:00
46829
5.190
True
Finance
765
Alice
NaN
False
1995-04-23
2017-05-17 06:35:00
148339
11.479
True
Finance
773
NaN
Male
True
1986-10-24
2017-05-17 09:23:00
47176
10.736
True
Finance
775
Rose
Female
False
1999-11-03
2017-05-17 09:06:00
75181
6.060
True
Finance
790
Fred
Male
True
1989-03-03
2017-05-17 02:27:00
129712
11.058
False
Finance
807
Mary
Female
False
2011-11-06
2017-05-17 08:32:00
115057
2.089
False
Finance
809
George
Male
True
1995-09-27
2017-05-17 17:04:00
36749
19.754
False
Finance
831
Kenneth
Male
True
2015-01-15
2017-05-17 14:41:00
69112
7.588
True
Finance
836
Carolyn
Female
False
2004-03-17
2017-05-17 06:38:00
118037
13.492
False
Finance
837
Joseph
Male
True
1985-05-23
2017-05-17 22:16:00
139570
15.804
True
Finance
847
Nicole
NaN
False
1981-05-02
2017-05-17 12:03:00
41449
4.707
False
Finance
854
Harry
Male
True
1985-02-10
2017-05-17 19:46:00
63046
10.411
False
Finance
856
Bonnie
NaN
False
2006-01-18
2017-05-17 18:52:00
108946
12.211
False
Finance
861
Jerry
Male
True
1989-03-26
2017-05-17 04:15:00
140850
18.855
False
Finance
880
Robert
NaN
False
2007-05-25
2017-05-17 03:17:00
90998
8.382
False
Finance
884
Lisa
Female
False
2003-10-17
2017-05-17 13:42:00
73706
18.530
False
Finance
889
Margaret
Female
False
2001-01-04
2017-05-17 03:07:00
126924
1.552
True
Finance
890
NaN
Male
True
2015-11-24
2017-05-17 03:11:00
145329
7.100
True
Finance
891
Timothy
Male
True
1991-08-25
2017-05-17 10:37:00
92587
8.475
False
Finance
897
Kenneth
NaN
False
1994-02-28
2017-05-17 10:10:00
95296
10.146
False
Finance
905
Alice
Female
False
2013-02-09
2017-05-17 00:49:00
121250
4.363
True
Finance
907
Elizabeth
Female
False
1998-07-27
2017-05-17 11:12:00
137144
10.081
False
Finance
954
Joe
Male
True
1980-01-19
2017-05-17 16:06:00
119667
1.148
True
Finance
987
Gloria
Female
False
2014-12-08
2017-05-17 05:08:00
136709
10.331
True
Finance
992
Anthony
Male
True
2011-10-16
2017-05-17 08:35:00
112769
11.625
True
Finance
996
Phillip
Male
True
1984-01-31
2017-05-17 06:30:00
42392
19.675
False
Finance
102 rows × 9 columns
In [52]:
df[df['Senior Management']]
Out[52]:
First Name
Gender
is_male
Start Date
Last Login Time
Salary
Bonus %
Senior Management
Team
0
Douglas
Male
True
1993-08-06
2017-05-17 12:42:00
97308
6.945
True
Marketing
1
Thomas
Male
True
1996-03-31
2017-05-17 06:53:00
61933
4.170
True
NaN
3
Jerry
Male
True
2005-03-04
2017-05-17 13:00:00
138705
9.340
True
Finance
4
Larry
Male
True
1998-01-24
2017-05-17 16:47:00
101004
1.389
True
Client Services
6
Ruby
Female
False
1987-08-17
2017-05-17 16:20:00
65476
10.012
True
Product
7
NaN
Female
False
2015-07-20
2017-05-17 10:43:00
45906
11.598
True
Finance
8
Angela
Female
False
2005-11-22
2017-05-17 06:29:00
95570
18.523
True
Engineering
9
Frances
Female
False
2002-08-08
2017-05-17 06:51:00
139852
7.524
True
Business Development
10
Louise
Female
False
1980-08-12
2017-05-17 09:01:00
63241
15.132
True
NaN
11
Julie
Female
False
1997-10-26
2017-05-17 15:19:00
102508
12.637
True
Legal
12
Brandon
Male
True
1980-12-01
2017-05-17 01:08:00
112807
17.492
True
Human Resources
14
Kimberly
Female
False
1999-01-14
2017-05-17 07:13:00
41426
14.543
True
Finance
20
Lois
NaN
False
1995-04-22
2017-05-17 19:18:00
64714
4.934
True
Legal
22
Joshua
NaN
False
2012-03-08
2017-05-17 01:58:00
90816
18.816
True
Client Services
23
NaN
Male
True
2012-06-14
2017-05-17 16:19:00
125792
5.042
True
NaN
25
NaN
Male
True
2012-10-08
2017-05-17 01:12:00
37076
18.576
True
Client Services
26
Craig
Male
True
2000-02-27
2017-05-17 07:45:00
37598
7.757
True
Marketing
28
Terry
Male
True
1981-11-27
2017-05-17 18:30:00
124008
13.464
True
Client Services
29
Benjamin
Male
True
2005-01-26
2017-05-17 22:06:00
79529
7.008
True
Legal
30
Christina
Female
False
2002-08-06
2017-05-17 13:19:00
118780
9.096
True
Engineering
32
NaN
Male
True
1998-08-21
2017-05-17 14:27:00
122340
6.417
True
NaN
37
Linda
Female
False
1981-10-19
2017-05-17 20:49:00
57427
9.557
True
Client Services
38
Stephanie
Female
False
1986-09-13
2017-05-17 01:52:00
36844
5.574
True
Business Development
39
NaN
Male
True
2016-01-29
2017-05-17 02:33:00
122173
7.797
True
Client Services
40
Michael
Male
True
2008-10-10
2017-05-17 11:25:00
99283
2.665
True
Distribution
41
Christine
NaN
False
2015-06-28
2017-05-17 01:08:00
66582
11.308
True
Business Development
43
Marilyn
Female
False
1980-12-07
2017-05-17 03:16:00
73524
5.207
True
Marketing
44
Cynthia
Female
False
1988-11-16
2017-05-17 18:54:00
145146
7.482
True
Product
45
Roger
Male
True
1980-04-17
2017-05-17 11:32:00
88010
13.886
True
Sales
47
Kathy
Female
False
2005-06-22
2017-05-17 04:51:00
66820
9.000
True
Client Services
...
...
...
...
...
...
...
...
...
...
945
Gerald
NaN
False
1989-04-15
2017-05-17 12:44:00
93712
17.426
True
Distribution
946
NaN
Female
False
1985-09-15
2017-05-17 01:50:00
133472
16.941
True
Distribution
947
NaN
Male
True
2012-07-30
2017-05-17 15:07:00
107351
5.329
True
Marketing
948
Ashley
Female
False
2006-03-31
2017-05-17 13:24:00
142410
11.048
True
Engineering
949
Scott
Male
True
2011-08-20
2017-05-17 08:08:00
37385
8.226
True
Business Development
951
NaN
Female
False
2010-09-14
2017-05-17 05:19:00
143638
9.662
True
NaN
952
Teresa
Female
False
2013-01-22
2017-05-17 15:17:00
113425
11.907
True
Human Resources
954
Joe
Male
True
1980-01-19
2017-05-17 16:06:00
119667
1.148
True
Finance
957
Jeffrey
Male
True
1984-02-03
2017-05-17 13:26:00
70990
15.901
True
Sales
959
Albert
Male
True
1992-09-19
2017-05-17 02:35:00
45094
5.850
True
Business Development
960
Stephen
Male
True
1989-10-29
2017-05-17 23:34:00
93997
18.093
True
Business Development
963
Ann
Female
False
1994-09-23
2017-05-17 11:15:00
89443
17.940
True
Sales
964
Bruce
Male
True
1980-05-07
2017-05-17 20:00:00
35802
12.391
True
Sales
966
Louis
Male
True
2011-08-16
2017-05-17 17:19:00
93022
9.146
True
Human Resources
969
Linda
Female
False
2010-02-04
2017-05-17 20:49:00
44486
17.308
True
Engineering
970
Alice
Female
False
1988-09-03
2017-05-17 20:54:00
63571
15.397
True
Product
971
Patrick
Male
True
2002-12-30
2017-05-17 02:01:00
75423
5.368
True
Business Development
972
Victor
NaN
False
2006-07-28
2017-05-17 14:49:00
76381
11.159
True
Sales
974
Harry
Male
True
2011-08-30
2017-05-17 18:31:00
67656
16.455
True
Client Services
976
Denise
Female
False
1992-10-19
2017-05-17 05:42:00
137954
4.195
True
Legal
979
Ernest
Male
True
2013-07-20
2017-05-17 06:41:00
142935
13.198
True
Product
980
Kimberly
Female
False
2013-01-26
2017-05-17 00:57:00
46233
8.862
True
Engineering
982
Rose
Female
False
1982-04-06
2017-05-17 10:43:00
91411
8.639
True
Human Resources
987
Gloria
Female
False
2014-12-08
2017-05-17 05:08:00
136709
10.331
True
Finance
990
Robin
Female
False
1987-07-24
2017-05-17 13:35:00
100765
10.982
True
Client Services
991
Rose
Female
False
2002-08-25
2017-05-17 05:12:00
134505
11.051
True
Marketing
992
Anthony
Male
True
2011-10-16
2017-05-17 08:35:00
112769
11.625
True
Finance
993
Tina
Female
False
1997-05-15
2017-05-17 15:53:00
56450
19.040
True
Engineering
994
George
Male
True
2013-06-21
2017-05-17 17:47:00
98874
4.479
True
Marketing
999
Albert
Male
True
2012-05-15
2017-05-17 18:24:00
129949
10.169
True
Sales
535 rows × 9 columns
In [54]:
df[df['Team'] != 'Finance'] # not equal to Finance
Out[54]:
First Name
Gender
is_male
Start Date
Last Login Time
Salary
Bonus %
Senior Management
Team
0
Douglas
Male
True
1993-08-06
2017-05-17 12:42:00
97308
6.945
True
Marketing
1
Thomas
Male
True
1996-03-31
2017-05-17 06:53:00
61933
4.170
True
NaN
4
Larry
Male
True
1998-01-24
2017-05-17 16:47:00
101004
1.389
True
Client Services
5
Dennis
Male
True
1987-04-18
2017-05-17 01:35:00
115163
10.125
False
Legal
6
Ruby
Female
False
1987-08-17
2017-05-17 16:20:00
65476
10.012
True
Product
8
Angela
Female
False
2005-11-22
2017-05-17 06:29:00
95570
18.523
True
Engineering
9
Frances
Female
False
2002-08-08
2017-05-17 06:51:00
139852
7.524
True
Business Development
10
Louise
Female
False
1980-08-12
2017-05-17 09:01:00
63241
15.132
True
NaN
11
Julie
Female
False
1997-10-26
2017-05-17 15:19:00
102508
12.637
True
Legal
12
Brandon
Male
True
1980-12-01
2017-05-17 01:08:00
112807
17.492
True
Human Resources
13
Gary
Male
True
2008-01-27
2017-05-17 23:40:00
109831
5.831
False
Sales
15
Lillian
Female
False
2016-06-05
2017-05-17 06:09:00
59414
1.256
False
Product
16
Jeremy
Male
True
2010-09-21
2017-05-17 05:56:00
90370
7.369
False
Human Resources
17
Shawn
Male
True
1986-12-07
2017-05-17 19:45:00
111737
6.414
False
Product
18
Diana
Female
False
1981-10-23
2017-05-17 10:27:00
132940
19.082
False
Client Services
19
Donna
Female
False
2010-07-22
2017-05-17 03:48:00
81014
1.894
False
Product
20
Lois
NaN
False
1995-04-22
2017-05-17 19:18:00
64714
4.934
True
Legal
21
Matthew
Male
True
1995-09-05
2017-05-17 02:12:00
100612
13.645
False
Marketing
22
Joshua
NaN
False
2012-03-08
2017-05-17 01:58:00
90816
18.816
True
Client Services
23
NaN
Male
True
2012-06-14
2017-05-17 16:19:00
125792
5.042
True
NaN
24
John
Male
True
1992-07-01
2017-05-17 22:08:00
97950
13.873
False
Client Services
25
NaN
Male
True
2012-10-08
2017-05-17 01:12:00
37076
18.576
True
Client Services
26
Craig
Male
True
2000-02-27
2017-05-17 07:45:00
37598
7.757
True
Marketing
27
Scott
NaN
False
1991-07-11
2017-05-17 18:58:00
122367
5.218
False
Legal
28
Terry
Male
True
1981-11-27
2017-05-17 18:30:00
124008
13.464
True
Client Services
29
Benjamin
Male
True
2005-01-26
2017-05-17 22:06:00
79529
7.008
True
Legal
30
Christina
Female
False
2002-08-06
2017-05-17 13:19:00
118780
9.096
True
Engineering
31
Joyce
NaN
False
2005-02-20
2017-05-17 14:40:00
88657
12.752
False
Product
32
NaN
Male
True
1998-08-21
2017-05-17 14:27:00
122340
6.417
True
NaN
33
Jean
Female
False
1993-12-18
2017-05-17 09:07:00
119082
16.180
False
Business Development
...
...
...
...
...
...
...
...
...
...
967
Thomas
Male
True
2016-03-12
2017-05-17 15:10:00
105681
19.572
False
Engineering
968
Louise
Female
False
1995-03-27
2017-05-17 22:27:00
43050
11.671
False
Distribution
969
Linda
Female
False
2010-02-04
2017-05-17 20:49:00
44486
17.308
True
Engineering
970
Alice
Female
False
1988-09-03
2017-05-17 20:54:00
63571
15.397
True
Product
971
Patrick
Male
True
2002-12-30
2017-05-17 02:01:00
75423
5.368
True
Business Development
972
Victor
NaN
False
2006-07-28
2017-05-17 14:49:00
76381
11.159
True
Sales
973
Russell
Male
True
2013-05-10
2017-05-17 23:08:00
137359
11.105
False
Business Development
974
Harry
Male
True
2011-08-30
2017-05-17 18:31:00
67656
16.455
True
Client Services
975
Susan
Female
False
1995-04-07
2017-05-17 22:05:00
92436
12.467
False
Sales
976
Denise
Female
False
1992-10-19
2017-05-17 05:42:00
137954
4.195
True
Legal
977
Sarah
Female
False
1995-12-04
2017-05-17 09:16:00
124566
5.949
False
Product
978
Sean
Male
True
1983-01-17
2017-05-17 14:23:00
66146
11.178
False
Human Resources
979
Ernest
Male
True
2013-07-20
2017-05-17 06:41:00
142935
13.198
True
Product
980
Kimberly
Female
False
2013-01-26
2017-05-17 00:57:00
46233
8.862
True
Engineering
981
James
Male
True
1993-01-15
2017-05-17 17:19:00
148985
19.280
False
Legal
982
Rose
Female
False
1982-04-06
2017-05-17 10:43:00
91411
8.639
True
Human Resources
983
John
Male
True
1982-12-23
2017-05-17 22:35:00
146907
11.738
False
Engineering
984
Maria
Female
False
2011-10-15
2017-05-17 16:53:00
43455
13.040
False
Engineering
985
Stephen
NaN
False
1983-07-10
2017-05-17 20:10:00
85668
1.909
False
Legal
986
Donna
Female
False
1982-11-26
2017-05-17 07:04:00
82871
17.999
False
Marketing
988
Alice
Female
False
2004-10-05
2017-05-17 09:34:00
47638
11.209
False
Human Resources
989
Justin
NaN
False
1991-02-10
2017-05-17 16:58:00
38344
3.794
False
Legal
990
Robin
Female
False
1987-07-24
2017-05-17 13:35:00
100765
10.982
True
Client Services
991
Rose
Female
False
2002-08-25
2017-05-17 05:12:00
134505
11.051
True
Marketing
993
Tina
Female
False
1997-05-15
2017-05-17 15:53:00
56450
19.040
True
Engineering
994
George
Male
True
2013-06-21
2017-05-17 17:47:00
98874
4.479
True
Marketing
995
Henry
NaN
False
2014-11-23
2017-05-17 06:09:00
132483
16.655
False
Distribution
997
Russell
Male
True
2013-05-20
2017-05-17 12:39:00
96914
1.421
False
Product
998
Larry
Male
True
2013-04-20
2017-05-17 16:45:00
60500
11.985
False
Business Development
999
Albert
Male
True
2012-05-15
2017-05-17 18:24:00
129949
10.169
True
Sales
898 rows × 9 columns
In [61]:
df[df['Salary'] > 149000]
Out[61]:
First Name
Gender
is_male
Start Date
Last Login Time
Salary
Bonus %
Senior Management
Team
160
Kathy
Female
False
2000-03-18
2017-05-17 19:26:00
149563
16.991
True
Finance
186
NaN
Female
False
2005-02-23
2017-05-17 21:50:00
149654
1.825
True
Sales
429
Rose
Female
False
2015-05-28
2017-05-17 08:40:00
149903
5.630
False
Human Resources
644
Katherine
Female
False
1996-08-13
2017-05-17 00:21:00
149908
18.912
False
Finance
740
Russell
NaN
False
2009-05-09
2017-05-17 11:59:00
149456
3.533
False
Marketing
793
Andrea
Female
False
1999-07-22
2017-05-17 09:25:00
149105
13.707
True
Distribution
828
Cynthia
Female
False
2006-07-12
2017-05-17 08:55:00
149684
7.864
False
Product
In [63]:
df[df['Bonus %'] < 1.2]
Out[63]:
First Name
Gender
is_male
Start Date
Last Login Time
Salary
Bonus %
Senior Management
Team
217
Douglas
Male
True
1999-09-03
2017-05-17 16:00:00
83341
1.015
True
Client Services
273
Nicholas
Male
True
1994-04-12
2017-05-17 20:21:00
74669
1.113
True
Product
279
Ruby
Female
False
2000-11-08
2017-05-17 19:35:00
105946
1.139
False
Business Development
365
Gloria
NaN
False
1983-07-19
2017-05-17 01:57:00
140885
1.113
False
Human Resources
481
NaN
Female
False
2013-04-27
2017-05-17 06:40:00
93847
1.085
True
Business Development
527
Helen
NaN
False
1993-12-02
2017-05-17 13:42:00
45724
1.022
False
Product
579
Harold
Male
True
2010-10-18
2017-05-17 20:45:00
65673
1.187
True
Legal
652
Willie
Male
True
2009-12-05
2017-05-17 05:39:00
141932
1.017
True
Engineering
708
Steve
Male
True
2002-01-11
2017-05-17 21:17:00
51821
1.197
True
Legal
746
Gloria
Female
False
2004-08-19
2017-05-17 10:31:00
46602
1.027
True
Business Development
912
Joe
Male
True
1998-12-08
2017-05-17 10:28:00
126120
1.020
False
NaN
929
Theresa
Female
False
2001-04-27
2017-05-17 21:17:00
75661
1.079
True
Legal
954
Joe
Male
True
1980-01-19
2017-05-17 16:06:00
119667
1.148
True
Finance
In [75]:
df[df['Start Date'] <= '1980-02-01' ]
Out[75]:
First Name
Gender
is_male
Start Date
Last Login Time
Salary
Bonus %
Senior Management
Team
49
Chris
NaN
False
1980-01-24
2017-05-17 12:13:00
113590
3.055
False
Sales
881
Ruby
Female
False
1980-01-28
2017-05-17 23:08:00
142868
6.318
False
Marketing
954
Joe
Male
True
1980-01-19
2017-05-17 16:06:00
119667
1.148
True
Finance
In [85]:
mask1 = df['Gender'] == 'Male'
mask2 = df['Team'] == 'Sales'
mask3 = df['Start Date'] <= '1980-02-01'
In [81]:
# AND OPERATOR
df[mask1 & mask2]
Out[81]:
First Name
Gender
is_male
Start Date
Last Login Time
Salary
Bonus %
Senior Management
Team
13
Gary
Male
True
2008-01-27
2017-05-17 23:40:00
109831
5.831
False
Sales
45
Roger
Male
True
1980-04-17
2017-05-17 11:32:00
88010
13.886
True
Sales
71
Johnny
Male
True
2009-11-06
2017-05-17 16:23:00
118172
16.194
True
Sales
167
Christopher
Male
True
2011-12-24
2017-05-17 12:22:00
142178
17.984
True
Sales
189
Clarence
Male
True
1998-05-02
2017-05-17 03:16:00
85700
1.215
False
Sales
202
Roger
Male
True
1982-11-08
2017-05-17 02:32:00
140558
5.084
True
Sales
225
Harry
Male
True
2015-10-01
2017-05-17 19:47:00
64579
15.266
True
Sales
257
NaN
Male
True
1999-11-25
2017-05-17 06:16:00
42676
15.517
True
Sales
312
Gerald
Male
True
2001-04-16
2017-05-17 22:09:00
121604
1.923
True
Sales
337
Earl
Male
True
2000-01-05
2017-05-17 17:46:00
91344
4.035
True
Sales
340
Steven
Male
True
2009-05-12
2017-05-17 14:14:00
113060
2.846
True
Sales
371
Larry
Male
True
2003-08-27
2017-05-17 13:00:00
91133
5.140
False
Sales
373
Kenneth
Male
True
1999-04-13
2017-05-17 22:28:00
81839
12.072
False
Sales
410
Ernest
Male
True
2012-08-14
2017-05-17 11:25:00
126232
6.191
True
Sales
421
Kevin
Male
True
1986-11-20
2017-05-17 18:59:00
79906
18.021
True
Sales
427
Frank
Male
True
1981-01-10
2017-05-17 13:30:00
71853
8.037
True
Sales
466
Walter
Male
True
2007-08-04
2017-05-17 13:59:00
58789
5.461
False
Sales
495
Eugene
Male
True
1984-05-24
2017-05-17 10:54:00
81077
2.117
False
Sales
515
Larry
Male
True
1999-01-08
2017-05-17 02:05:00
97370
10.458
False
Sales
539
Justin
Male
True
1999-09-06
2017-05-17 10:30:00
62454
3.459
True
Sales
592
Justin
Male
True
1981-05-24
2017-05-17 23:15:00
78351
15.221
False
Sales
607
NaN
Male
True
1983-10-13
2017-05-17 23:59:00
139754
12.740
True
Sales
609
Todd
Male
True
2010-02-16
2017-05-17 11:29:00
103405
15.910
False
Sales
624
Jeremy
Male
True
1997-11-26
2017-05-17 08:22:00
133033
12.200
False
Sales
690
Bruce
Male
True
2007-01-28
2017-05-17 23:10:00
134988
13.926
True
Sales
692
Harold
Male
True
2007-05-15
2017-05-17 18:37:00
118753
8.162
False
Sales
727
Roy
Male
True
2004-05-10
2017-05-17 13:22:00
46875
12.942
True
Sales
739
Carlos
Male
True
1981-01-25
2017-05-17 10:00:00
138598
14.737
False
Sales
764
Roger
Male
True
1988-05-02
2017-05-17 22:04:00
115582
15.343
True
Sales
787
Kevin
Male
True
2005-07-01
2017-05-17 15:22:00
141498
4.135
True
Sales
862
Ronald
Male
True
1983-05-25
2017-05-17 10:05:00
50426
18.536
True
Sales
873
Jason
Male
True
1998-05-01
2017-05-17 18:05:00
75607
4.299
True
Sales
886
Anthony
Male
True
2014-01-30
2017-05-17 21:04:00
96795
14.837
False
Sales
892
Brandon
Male
True
1995-10-23
2017-05-17 12:04:00
60263
2.709
False
Sales
896
Victor
Male
True
2010-03-10
2017-05-17 17:01:00
45267
3.942
True
Sales
921
George
Male
True
2015-06-05
2017-05-17 05:40:00
50369
18.900
True
Sales
957
Jeffrey
Male
True
1984-02-03
2017-05-17 13:26:00
70990
15.901
True
Sales
964
Bruce
Male
True
1980-05-07
2017-05-17 20:00:00
35802
12.391
True
Sales
999
Albert
Male
True
2012-05-15
2017-05-17 18:24:00
129949
10.169
True
Sales
In [82]:
# OR OPERATOR
df[mask1 | mask2]
Out[82]:
First Name
Gender
is_male
Start Date
Last Login Time
Salary
Bonus %
Senior Management
Team
0
Douglas
Male
True
1993-08-06
2017-05-17 12:42:00
97308
6.945
True
Marketing
1
Thomas
Male
True
1996-03-31
2017-05-17 06:53:00
61933
4.170
True
NaN
3
Jerry
Male
True
2005-03-04
2017-05-17 13:00:00
138705
9.340
True
Finance
4
Larry
Male
True
1998-01-24
2017-05-17 16:47:00
101004
1.389
True
Client Services
5
Dennis
Male
True
1987-04-18
2017-05-17 01:35:00
115163
10.125
False
Legal
12
Brandon
Male
True
1980-12-01
2017-05-17 01:08:00
112807
17.492
True
Human Resources
13
Gary
Male
True
2008-01-27
2017-05-17 23:40:00
109831
5.831
False
Sales
16
Jeremy
Male
True
2010-09-21
2017-05-17 05:56:00
90370
7.369
False
Human Resources
17
Shawn
Male
True
1986-12-07
2017-05-17 19:45:00
111737
6.414
False
Product
21
Matthew
Male
True
1995-09-05
2017-05-17 02:12:00
100612
13.645
False
Marketing
23
NaN
Male
True
2012-06-14
2017-05-17 16:19:00
125792
5.042
True
NaN
24
John
Male
True
1992-07-01
2017-05-17 22:08:00
97950
13.873
False
Client Services
25
NaN
Male
True
2012-10-08
2017-05-17 01:12:00
37076
18.576
True
Client Services
26
Craig
Male
True
2000-02-27
2017-05-17 07:45:00
37598
7.757
True
Marketing
28
Terry
Male
True
1981-11-27
2017-05-17 18:30:00
124008
13.464
True
Client Services
29
Benjamin
Male
True
2005-01-26
2017-05-17 22:06:00
79529
7.008
True
Legal
32
NaN
Male
True
1998-08-21
2017-05-17 14:27:00
122340
6.417
True
NaN
34
Jerry
Male
True
2004-01-10
2017-05-17 12:56:00
95734
19.096
False
Client Services
35
Theresa
Female
False
2006-10-10
2017-05-17 01:12:00
85182
16.675
False
Sales
39
NaN
Male
True
2016-01-29
2017-05-17 02:33:00
122173
7.797
True
Client Services
40
Michael
Male
True
2008-10-10
2017-05-17 11:25:00
99283
2.665
True
Distribution
45
Roger
Male
True
1980-04-17
2017-05-17 11:32:00
88010
13.886
True
Sales
46
Bruce
Male
True
2009-11-28
2017-05-17 22:47:00
114796
6.796
False
Finance
48
Clarence
Male
True
1996-03-26
2017-05-17 05:57:00
93581
6.083
True
Business Development
49
Chris
NaN
False
1980-01-24
2017-05-17 12:13:00
113590
3.055
False
Sales
51
NaN
NaN
False
2011-12-17
2017-05-17 08:29:00
41126
14.009
True
Sales
52
Todd
Male
True
1990-02-18
2017-05-17 02:41:00
49339
1.695
True
Human Resources
56
Carl
Male
True
2006-05-03
2017-05-17 17:55:00
130276
16.084
True
Finance
57
Henry
Male
True
1996-06-26
2017-05-17 01:44:00
64715
15.107
True
Human Resources
63
Matthew
Male
True
2013-01-02
2017-05-17 22:33:00
35203
18.040
False
Human Resources
...
...
...
...
...
...
...
...
...
...
941
William
Male
True
1997-06-26
2017-05-17 08:33:00
104840
15.653
True
Engineering
943
Wayne
Male
True
2006-09-08
2017-05-17 11:09:00
67471
2.728
False
Engineering
944
Kenneth
Male
True
2006-05-10
2017-05-17 08:24:00
101914
1.905
True
Distribution
947
NaN
Male
True
2012-07-30
2017-05-17 15:07:00
107351
5.329
True
Marketing
949
Scott
Male
True
2011-08-20
2017-05-17 08:08:00
37385
8.226
True
Business Development
953
Randy
Male
True
2012-02-25
2017-05-17 05:33:00
57266
14.077
False
Product
954
Joe
Male
True
1980-01-19
2017-05-17 16:06:00
119667
1.148
True
Finance
957
Jeffrey
Male
True
1984-02-03
2017-05-17 13:26:00
70990
15.901
True
Sales
959
Albert
Male
True
1992-09-19
2017-05-17 02:35:00
45094
5.850
True
Business Development
960
Stephen
Male
True
1989-10-29
2017-05-17 23:34:00
93997
18.093
True
Business Development
962
Jonathan
Male
True
2013-08-21
2017-05-17 00:45:00
121797
16.923
False
Product
963
Ann
Female
False
1994-09-23
2017-05-17 11:15:00
89443
17.940
True
Sales
964
Bruce
Male
True
1980-05-07
2017-05-17 20:00:00
35802
12.391
True
Sales
966
Louis
Male
True
2011-08-16
2017-05-17 17:19:00
93022
9.146
True
Human Resources
967
Thomas
Male
True
2016-03-12
2017-05-17 15:10:00
105681
19.572
False
Engineering
971
Patrick
Male
True
2002-12-30
2017-05-17 02:01:00
75423
5.368
True
Business Development
972
Victor
NaN
False
2006-07-28
2017-05-17 14:49:00
76381
11.159
True
Sales
973
Russell
Male
True
2013-05-10
2017-05-17 23:08:00
137359
11.105
False
Business Development
974
Harry
Male
True
2011-08-30
2017-05-17 18:31:00
67656
16.455
True
Client Services
975
Susan
Female
False
1995-04-07
2017-05-17 22:05:00
92436
12.467
False
Sales
978
Sean
Male
True
1983-01-17
2017-05-17 14:23:00
66146
11.178
False
Human Resources
979
Ernest
Male
True
2013-07-20
2017-05-17 06:41:00
142935
13.198
True
Product
981
James
Male
True
1993-01-15
2017-05-17 17:19:00
148985
19.280
False
Legal
983
John
Male
True
1982-12-23
2017-05-17 22:35:00
146907
11.738
False
Engineering
992
Anthony
Male
True
2011-10-16
2017-05-17 08:35:00
112769
11.625
True
Finance
994
George
Male
True
2013-06-21
2017-05-17 17:47:00
98874
4.479
True
Marketing
996
Phillip
Male
True
1984-01-31
2017-05-17 06:30:00
42392
19.675
False
Finance
997
Russell
Male
True
2013-05-20
2017-05-17 12:39:00
96914
1.421
False
Product
998
Larry
Male
True
2013-04-20
2017-05-17 16:45:00
60500
11.985
False
Business Development
999
Albert
Male
True
2012-05-15
2017-05-17 18:24:00
129949
10.169
True
Sales
479 rows × 9 columns
In [87]:
df[(mask1 | mask2) & mask3]
Out[87]:
First Name
Gender
is_male
Start Date
Last Login Time
Salary
Bonus %
Senior Management
Team
49
Chris
NaN
False
1980-01-24
2017-05-17 12:13:00
113590
3.055
False
Sales
954
Joe
Male
True
1980-01-19
2017-05-17 16:06:00
119667
1.148
True
Finance
In [88]:
df = pd.read_csv('data/employees.csv', parse_dates=['Start Date', 'Last Login Time'])
df['Gender'] = df['Gender'].astype('category')
df['Team'] = df['Team'].astype('category')
df['Senior Management'] = df['Senior Management'].astype('bool')
df.head()
Out[88]:
First Name
Gender
Start Date
Last Login Time
Salary
Bonus %
Senior Management
Team
0
Douglas
Male
1993-08-06
2017-05-17 12:42:00
97308
6.945
True
Marketing
1
Thomas
Male
1996-03-31
2017-05-17 06:53:00
61933
4.170
True
NaN
2
Maria
Female
1993-04-23
2017-05-17 11:17:00
130590
11.858
False
Finance
3
Jerry
Male
2005-03-04
2017-05-17 13:00:00
138705
9.340
True
Finance
4
Larry
Male
1998-01-24
2017-05-17 16:47:00
101004
1.389
True
Client Services
In [90]:
mask1 = df['Team'] == 'Legal'
mask2 = df['Team'] == 'Sales'
mask3 = df['Team'] == 'Product'
In [91]:
# Bad version...
df[mask1 | mask2 | mask3]
Out[91]:
First Name
Gender
Start Date
Last Login Time
Salary
Bonus %
Senior Management
Team
6
Ruby
Female
1987-08-17
2017-05-17 16:20:00
65476
10.012
True
Product
13
Gary
Male
2008-01-27
2017-05-17 23:40:00
109831
5.831
False
Sales
15
Lillian
Female
2016-06-05
2017-05-17 06:09:00
59414
1.256
False
Product
17
Shawn
Male
1986-12-07
2017-05-17 19:45:00
111737
6.414
False
Product
19
Donna
Female
2010-07-22
2017-05-17 03:48:00
81014
1.894
False
Product
31
Joyce
NaN
2005-02-20
2017-05-17 14:40:00
88657
12.752
False
Product
35
Theresa
Female
2006-10-10
2017-05-17 01:12:00
85182
16.675
False
Sales
44
Cynthia
Female
1988-11-16
2017-05-17 18:54:00
145146
7.482
True
Product
45
Roger
Male
1980-04-17
2017-05-17 11:32:00
88010
13.886
True
Sales
49
Chris
NaN
1980-01-24
2017-05-17 12:13:00
113590
3.055
False
Sales
51
NaN
NaN
2011-12-17
2017-05-17 08:29:00
41126
14.009
True
Sales
55
Karen
Female
1999-11-30
2017-05-17 07:46:00
102488
17.653
True
Product
71
Johnny
Male
2009-11-06
2017-05-17 16:23:00
118172
16.194
True
Sales
72
Bobby
Male
2007-05-07
2017-05-17 10:01:00
54043
3.833
False
Product
73
Frances
Female
1999-04-04
2017-05-17 16:19:00
90582
4.709
True
Sales
78
Robin
Female
1983-06-04
2017-05-17 15:15:00
114797
5.965
True
Sales
79
Bonnie
Female
1988-11-13
2017-05-17 15:30:00
115814
4.990
False
Product
80
Gerald
NaN
1995-03-17
2017-05-17 00:50:00
137126
15.602
True
Sales
87
Annie
Female
1993-01-30
2017-05-17 02:05:00
144887
8.276
True
Sales
115
Pamela
Female
1982-07-01
2017-05-17 06:51:00
54585
4.166
False
Product
121
Kathleen
NaN
2016-05-09
2017-05-17 08:55:00
119735
18.740
False
Product
123
Helen
Female
2001-11-29
2017-05-17 02:30:00
73789
14.841
True
Product
124
Marilyn
Female
1983-11-16
2017-05-17 08:29:00
76078
2.401
True
Product
131
Rebecca
Female
1992-07-10
2017-05-17 00:23:00
94231
17.517
False
Product
141
Adam
Male
1990-12-24
2017-05-17 20:57:00
110194
14.727
True
Product
144
Nicole
NaN
1982-03-05
2017-05-17 14:28:00
122717
12.452
False
Sales
146
Patricia
Female
1992-11-25
2017-05-17 02:24:00
95322
4.150
False
Product
148
Patrick
NaN
1991-07-14
2017-05-17 02:24:00
124488
14.837
True
Sales
154
Rebecca
Female
1980-11-15
2017-05-17 04:13:00
85730
5.359
True
Product
157
NaN
Female
2005-07-27
2017-05-17 08:32:00
79536
14.443
True
Product
...
...
...
...
...
...
...
...
...
843
Louise
Female
1982-02-26
2017-05-17 01:03:00
106362
8.965
False
Sales
848
Bobby
Male
1984-06-05
2017-05-17 07:40:00
93368
2.880
True
Product
849
Ernest
Male
1997-09-06
2017-05-17 14:02:00
53335
9.192
False
Product
857
Marie
Female
1993-12-08
2017-05-17 18:28:00
98406
7.943
True
Product
862
Ronald
Male
1983-05-25
2017-05-17 10:05:00
50426
18.536
True
Sales
868
Katherine
Female
2013-08-18
2017-05-17 15:58:00
97443
13.657
False
Product
873
Jason
Male
1998-05-01
2017-05-17 18:05:00
75607
4.299
True
Sales
881
Ruby
Female
1980-01-28
2017-05-17 23:08:00
142868
6.318
False
Marketing
885
Juan
Male
1993-10-06
2017-05-17 08:52:00
85871
9.160
False
Product
886
Anthony
Male
2014-01-30
2017-05-17 21:04:00
96795
14.837
False
Sales
892
Brandon
Male
1995-10-23
2017-05-17 12:04:00
60263
2.709
False
Sales
896
Victor
Male
2010-03-10
2017-05-17 17:01:00
45267
3.942
True
Sales
906
Frances
Female
2014-05-16
2017-05-17 08:31:00
35884
17.667
False
Sales
909
Donald
Male
1991-08-01
2017-05-17 02:25:00
61999
6.466
False
Product
917
Shawn
Male
2008-03-13
2017-05-17 17:36:00
51667
6.339
False
Product
921
George
Male
2015-06-05
2017-05-17 05:40:00
50369
18.900
True
Sales
925
NaN
Female
2000-08-23
2017-05-17 16:19:00
95866
19.388
True
Sales
953
Randy
Male
2012-02-25
2017-05-17 05:33:00
57266
14.077
False
Product
954
Joe
Male
1980-01-19
2017-05-17 16:06:00
119667
1.148
True
Finance
957
Jeffrey
Male
1984-02-03
2017-05-17 13:26:00
70990
15.901
True
Sales
962
Jonathan
Male
2013-08-21
2017-05-17 00:45:00
121797
16.923
False
Product
963
Ann
Female
1994-09-23
2017-05-17 11:15:00
89443
17.940
True
Sales
964
Bruce
Male
1980-05-07
2017-05-17 20:00:00
35802
12.391
True
Sales
970
Alice
Female
1988-09-03
2017-05-17 20:54:00
63571
15.397
True
Product
972
Victor
NaN
2006-07-28
2017-05-17 14:49:00
76381
11.159
True
Sales
975
Susan
Female
1995-04-07
2017-05-17 22:05:00
92436
12.467
False
Sales
977
Sarah
Female
1995-12-04
2017-05-17 09:16:00
124566
5.949
False
Product
979
Ernest
Male
2013-07-20
2017-05-17 06:41:00
142935
13.198
True
Product
997
Russell
Male
2013-05-20
2017-05-17 12:39:00
96914
1.421
False
Product
999
Albert
Male
2012-05-15
2017-05-17 18:24:00
129949
10.169
True
Sales
191 rows × 8 columns
In [94]:
# isin() is better for multiple values!
df['Team'].isin(['Legal', 'Sales', 'Product'])
Out[94]:
0 False
1 False
2 False
3 False
4 False
5 True
6 True
7 False
8 False
9 False
10 False
11 True
12 False
13 True
14 False
15 True
16 False
17 True
18 False
19 True
20 True
21 False
22 False
23 False
24 False
25 False
26 False
27 True
28 False
29 True
...
970 True
971 False
972 True
973 False
974 False
975 True
976 True
977 True
978 False
979 True
980 False
981 True
982 False
983 False
984 False
985 True
986 False
987 False
988 False
989 True
990 False
991 False
992 False
993 False
994 False
995 False
996 False
997 True
998 False
999 True
Name: Team, Length: 1000, dtype: bool
In [95]:
mask = df['Team'].isin(['Legal', 'Sales', 'Product'])
df[mask]
Out[95]:
First Name
Gender
Start Date
Last Login Time
Salary
Bonus %
Senior Management
Team
5
Dennis
Male
1987-04-18
2017-05-17 01:35:00
115163
10.125
False
Legal
6
Ruby
Female
1987-08-17
2017-05-17 16:20:00
65476
10.012
True
Product
11
Julie
Female
1997-10-26
2017-05-17 15:19:00
102508
12.637
True
Legal
13
Gary
Male
2008-01-27
2017-05-17 23:40:00
109831
5.831
False
Sales
15
Lillian
Female
2016-06-05
2017-05-17 06:09:00
59414
1.256
False
Product
17
Shawn
Male
1986-12-07
2017-05-17 19:45:00
111737
6.414
False
Product
19
Donna
Female
2010-07-22
2017-05-17 03:48:00
81014
1.894
False
Product
20
Lois
NaN
1995-04-22
2017-05-17 19:18:00
64714
4.934
True
Legal
27
Scott
NaN
1991-07-11
2017-05-17 18:58:00
122367
5.218
False
Legal
29
Benjamin
Male
2005-01-26
2017-05-17 22:06:00
79529
7.008
True
Legal
31
Joyce
NaN
2005-02-20
2017-05-17 14:40:00
88657
12.752
False
Product
35
Theresa
Female
2006-10-10
2017-05-17 01:12:00
85182
16.675
False
Sales
42
Beverly
Female
1998-09-09
2017-05-17 20:26:00
121918
15.835
False
Legal
44
Cynthia
Female
1988-11-16
2017-05-17 18:54:00
145146
7.482
True
Product
45
Roger
Male
1980-04-17
2017-05-17 11:32:00
88010
13.886
True
Sales
49
Chris
NaN
1980-01-24
2017-05-17 12:13:00
113590
3.055
False
Sales
51
NaN
NaN
2011-12-17
2017-05-17 08:29:00
41126
14.009
True
Sales
55
Karen
Female
1999-11-30
2017-05-17 07:46:00
102488
17.653
True
Product
71
Johnny
Male
2009-11-06
2017-05-17 16:23:00
118172
16.194
True
Sales
72
Bobby
Male
2007-05-07
2017-05-17 10:01:00
54043
3.833
False
Product
73
Frances
Female
1999-04-04
2017-05-17 16:19:00
90582
4.709
True
Sales
78
Robin
Female
1983-06-04
2017-05-17 15:15:00
114797
5.965
True
Sales
79
Bonnie
Female
1988-11-13
2017-05-17 15:30:00
115814
4.990
False
Product
80
Gerald
NaN
1995-03-17
2017-05-17 00:50:00
137126
15.602
True
Sales
81
Christopher
Male
2008-03-30
2017-05-17 10:52:00
47369
14.822
False
Legal
87
Annie
Female
1993-01-30
2017-05-17 02:05:00
144887
8.276
True
Sales
88
Donna
Female
1991-11-27
2017-05-17 13:59:00
64088
6.155
True
Legal
89
Janice
Female
2016-03-12
2017-05-17 00:40:00
51082
11.955
False
Legal
90
Janice
NaN
1997-08-21
2017-05-17 05:12:00
91719
11.583
True
Legal
93
Virginia
NaN
1994-05-07
2017-05-17 17:58:00
111858
1.601
True
Legal
...
...
...
...
...
...
...
...
...
886
Anthony
Male
2014-01-30
2017-05-17 21:04:00
96795
14.837
False
Sales
887
David
Male
2009-12-05
2017-05-17 08:48:00
92242
15.407
False
Legal
888
Marilyn
Female
2007-10-08
2017-05-17 00:32:00
115149
11.934
True
Legal
892
Brandon
Male
1995-10-23
2017-05-17 12:04:00
60263
2.709
False
Sales
896
Victor
Male
2010-03-10
2017-05-17 17:01:00
45267
3.942
True
Sales
906
Frances
Female
2014-05-16
2017-05-17 08:31:00
35884
17.667
False
Sales
909
Donald
Male
1991-08-01
2017-05-17 02:25:00
61999
6.466
False
Product
910
Melissa
Female
2002-10-22
2017-05-17 01:20:00
45223
8.879
True
Legal
917
Shawn
Male
2008-03-13
2017-05-17 17:36:00
51667
6.339
False
Product
921
George
Male
2015-06-05
2017-05-17 05:40:00
50369
18.900
True
Sales
925
NaN
Female
2000-08-23
2017-05-17 16:19:00
95866
19.388
True
Sales
929
Theresa
Female
2001-04-27
2017-05-17 21:17:00
75661
1.079
True
Legal
953
Randy
Male
2012-02-25
2017-05-17 05:33:00
57266
14.077
False
Product
955
Sarah
Female
2014-08-17
2017-05-17 23:08:00
127118
11.176
False
Legal
957
Jeffrey
Male
1984-02-03
2017-05-17 13:26:00
70990
15.901
True
Sales
961
Antonio
NaN
1989-06-18
2017-05-17 21:37:00
103050
3.050
False
Legal
962
Jonathan
Male
2013-08-21
2017-05-17 00:45:00
121797
16.923
False
Product
963
Ann
Female
1994-09-23
2017-05-17 11:15:00
89443
17.940
True
Sales
964
Bruce
Male
1980-05-07
2017-05-17 20:00:00
35802
12.391
True
Sales
970
Alice
Female
1988-09-03
2017-05-17 20:54:00
63571
15.397
True
Product
972
Victor
NaN
2006-07-28
2017-05-17 14:49:00
76381
11.159
True
Sales
975
Susan
Female
1995-04-07
2017-05-17 22:05:00
92436
12.467
False
Sales
976
Denise
Female
1992-10-19
2017-05-17 05:42:00
137954
4.195
True
Legal
977
Sarah
Female
1995-12-04
2017-05-17 09:16:00
124566
5.949
False
Product
979
Ernest
Male
2013-07-20
2017-05-17 06:41:00
142935
13.198
True
Product
981
James
Male
1993-01-15
2017-05-17 17:19:00
148985
19.280
False
Legal
985
Stephen
NaN
1983-07-10
2017-05-17 20:10:00
85668
1.909
False
Legal
989
Justin
NaN
1991-02-10
2017-05-17 16:58:00
38344
3.794
False
Legal
997
Russell
Male
2013-05-20
2017-05-17 12:39:00
96914
1.421
False
Product
999
Albert
Male
2012-05-15
2017-05-17 18:24:00
129949
10.169
True
Sales
277 rows × 8 columns
In [97]:
df = pd.read_csv('data/employees.csv', parse_dates=['Start Date', 'Last Login Time'])
df['Gender'] = df['Gender'].astype('category')
df['Team'] = df['Team'].astype('category')
df['Senior Management'] = df['Senior Management'].astype('bool')
df.head(3)
Out[97]:
First Name
Gender
Start Date
Last Login Time
Salary
Bonus %
Senior Management
Team
0
Douglas
Male
1993-08-06
2017-05-17 12:42:00
97308
6.945
True
Marketing
1
Thomas
Male
1996-03-31
2017-05-17 06:53:00
61933
4.170
True
NaN
2
Maria
Female
1993-04-23
2017-05-17 11:17:00
130590
11.858
False
Finance
In [99]:
df[df['Gender'].isnull()]
Out[99]:
First Name
Gender
Start Date
Last Login Time
Salary
Bonus %
Senior Management
Team
20
Lois
NaN
1995-04-22
2017-05-17 19:18:00
64714
4.934
True
Legal
22
Joshua
NaN
2012-03-08
2017-05-17 01:58:00
90816
18.816
True
Client Services
27
Scott
NaN
1991-07-11
2017-05-17 18:58:00
122367
5.218
False
Legal
31
Joyce
NaN
2005-02-20
2017-05-17 14:40:00
88657
12.752
False
Product
41
Christine
NaN
2015-06-28
2017-05-17 01:08:00
66582
11.308
True
Business Development
49
Chris
NaN
1980-01-24
2017-05-17 12:13:00
113590
3.055
False
Sales
51
NaN
NaN
2011-12-17
2017-05-17 08:29:00
41126
14.009
True
Sales
53
Alan
NaN
2014-03-03
2017-05-17 13:28:00
40341
17.578
True
Finance
60
Paula
NaN
2005-11-23
2017-05-17 14:01:00
48866
4.271
False
Distribution
64
Kathleen
NaN
1990-04-11
2017-05-17 18:46:00
77834
18.771
False
Business Development
69
Irene
NaN
2015-07-14
2017-05-17 16:31:00
100863
4.382
True
Finance
70
Todd
NaN
2003-06-10
2017-05-17 14:26:00
84692
6.617
False
Client Services
80
Gerald
NaN
1995-03-17
2017-05-17 00:50:00
137126
15.602
True
Sales
86
Annie
NaN
2007-09-29
2017-05-17 00:11:00
103495
17.290
True
Business Development
90
Janice
NaN
1997-08-21
2017-05-17 05:12:00
91719
11.583
True
Legal
91
James
NaN
2005-01-26
2017-05-17 23:00:00
128771
8.309
False
NaN
93
Virginia
NaN
1994-05-07
2017-05-17 17:58:00
111858
1.601
True
Legal
97
Laura
NaN
2014-07-19
2017-05-17 21:23:00
140371
10.620
True
Marketing
108
Russell
NaN
1988-05-05
2017-05-17 07:57:00
133980
12.396
True
Legal
121
Kathleen
NaN
2016-05-09
2017-05-17 08:55:00
119735
18.740
False
Product
143
Teresa
NaN
2016-01-28
2017-05-17 10:55:00
140013
8.689
True
Engineering
144
Nicole
NaN
1982-03-05
2017-05-17 14:28:00
122717
12.452
False
Sales
148
Patrick
NaN
1991-07-14
2017-05-17 02:24:00
124488
14.837
True
Sales
151
Brandon
NaN
1997-11-03
2017-05-17 20:17:00
121333
15.295
False
Business Development
153
Victor
NaN
2011-03-10
2017-05-17 20:40:00
84546
10.489
True
Finance
159
James
NaN
1983-11-22
2017-05-17 22:52:00
68501
14.316
False
Marketing
161
Marilyn
NaN
1999-08-22
2017-05-17 09:09:00
103386
11.451
False
Distribution
168
Peter
NaN
1987-09-03
2017-05-17 17:59:00
38989
7.017
True
Marketing
174
NaN
NaN
2007-09-18
2017-05-17 18:59:00
40297
6.185
True
Client Services
183
Ruth
NaN
1999-05-18
2017-05-17 05:56:00
98233
2.518
True
Distribution
...
...
...
...
...
...
...
...
...
769
Samuel
NaN
2002-10-07
2017-05-17 03:08:00
141305
9.849
True
Marketing
783
NaN
NaN
1991-04-15
2017-05-17 03:39:00
132505
13.592
True
Product
788
Michelle
NaN
2012-03-31
2017-05-17 06:28:00
124441
16.353
False
Business Development
792
Anne
NaN
1996-04-18
2017-05-17 23:57:00
122762
9.564
False
Distribution
795
Theresa
NaN
1995-10-07
2017-05-17 10:16:00
42025
3.319
True
Human Resources
815
Maria
NaN
1986-01-18
2017-05-17 20:36:00
106562
4.000
False
Human Resources
825
Robert
NaN
2000-12-04
2017-05-17 01:20:00
69267
5.890
True
Sales
826
NaN
NaN
1988-08-01
2017-05-17 01:35:00
87103
5.665
True
NaN
827
Jesse
NaN
2014-07-16
2017-05-17 02:24:00
98811
7.487
False
Legal
834
Carl
NaN
1982-02-11
2017-05-17 07:54:00
49325
2.071
True
Business Development
844
Maria
NaN
1985-06-19
2017-05-17 01:48:00
148857
8.738
False
Legal
847
Nicole
NaN
1981-05-02
2017-05-17 12:03:00
41449
4.707
False
Finance
855
Phillip
NaN
2003-10-20
2017-05-17 11:09:00
89700
2.277
True
NaN
856
Bonnie
NaN
2006-01-18
2017-05-17 18:52:00
108946
12.211
False
Finance
870
Cynthia
NaN
1996-11-19
2017-05-17 22:40:00
107816
18.751
False
Marketing
876
Terry
NaN
1992-09-11
2017-05-17 16:41:00
41238
8.219
False
Marketing
880
Robert
NaN
2007-05-25
2017-05-17 03:17:00
90998
8.382
False
Finance
882
Sara
NaN
2014-11-18
2017-05-17 14:47:00
135990
14.344
True
Distribution
895
Janice
NaN
1991-11-19
2017-05-17 18:02:00
139791
16.968
False
Business Development
897
Kenneth
NaN
1994-02-28
2017-05-17 10:10:00
95296
10.146
False
Finance
923
Irene
NaN
1991-02-28
2017-05-17 22:23:00
135369
4.380
False
Business Development
937
Aaron
NaN
1986-01-22
2017-05-17 19:39:00
63126
18.424
False
Client Services
938
Mark
NaN
2006-09-09
2017-05-17 12:27:00
44836
2.657
False
Client Services
939
Ralph
NaN
1995-07-28
2017-05-17 18:53:00
70635
2.147
False
Client Services
945
Gerald
NaN
1989-04-15
2017-05-17 12:44:00
93712
17.426
True
Distribution
961
Antonio
NaN
1989-06-18
2017-05-17 21:37:00
103050
3.050
False
Legal
972
Victor
NaN
2006-07-28
2017-05-17 14:49:00
76381
11.159
True
Sales
985
Stephen
NaN
1983-07-10
2017-05-17 20:10:00
85668
1.909
False
Legal
989
Justin
NaN
1991-02-10
2017-05-17 16:58:00
38344
3.794
False
Legal
995
Henry
NaN
2014-11-23
2017-05-17 06:09:00
132483
16.655
False
Distribution
145 rows × 8 columns
In [101]:
df[df['Gender'].notnull()]
Out[101]:
First Name
Gender
Start Date
Last Login Time
Salary
Bonus %
Senior Management
Team
0
Douglas
Male
1993-08-06
2017-05-17 12:42:00
97308
6.945
True
Marketing
1
Thomas
Male
1996-03-31
2017-05-17 06:53:00
61933
4.170
True
NaN
2
Maria
Female
1993-04-23
2017-05-17 11:17:00
130590
11.858
False
Finance
3
Jerry
Male
2005-03-04
2017-05-17 13:00:00
138705
9.340
True
Finance
4
Larry
Male
1998-01-24
2017-05-17 16:47:00
101004
1.389
True
Client Services
5
Dennis
Male
1987-04-18
2017-05-17 01:35:00
115163
10.125
False
Legal
6
Ruby
Female
1987-08-17
2017-05-17 16:20:00
65476
10.012
True
Product
7
NaN
Female
2015-07-20
2017-05-17 10:43:00
45906
11.598
True
Finance
8
Angela
Female
2005-11-22
2017-05-17 06:29:00
95570
18.523
True
Engineering
9
Frances
Female
2002-08-08
2017-05-17 06:51:00
139852
7.524
True
Business Development
10
Louise
Female
1980-08-12
2017-05-17 09:01:00
63241
15.132
True
NaN
11
Julie
Female
1997-10-26
2017-05-17 15:19:00
102508
12.637
True
Legal
12
Brandon
Male
1980-12-01
2017-05-17 01:08:00
112807
17.492
True
Human Resources
13
Gary
Male
2008-01-27
2017-05-17 23:40:00
109831
5.831
False
Sales
14
Kimberly
Female
1999-01-14
2017-05-17 07:13:00
41426
14.543
True
Finance
15
Lillian
Female
2016-06-05
2017-05-17 06:09:00
59414
1.256
False
Product
16
Jeremy
Male
2010-09-21
2017-05-17 05:56:00
90370
7.369
False
Human Resources
17
Shawn
Male
1986-12-07
2017-05-17 19:45:00
111737
6.414
False
Product
18
Diana
Female
1981-10-23
2017-05-17 10:27:00
132940
19.082
False
Client Services
19
Donna
Female
2010-07-22
2017-05-17 03:48:00
81014
1.894
False
Product
21
Matthew
Male
1995-09-05
2017-05-17 02:12:00
100612
13.645
False
Marketing
23
NaN
Male
2012-06-14
2017-05-17 16:19:00
125792
5.042
True
NaN
24
John
Male
1992-07-01
2017-05-17 22:08:00
97950
13.873
False
Client Services
25
NaN
Male
2012-10-08
2017-05-17 01:12:00
37076
18.576
True
Client Services
26
Craig
Male
2000-02-27
2017-05-17 07:45:00
37598
7.757
True
Marketing
28
Terry
Male
1981-11-27
2017-05-17 18:30:00
124008
13.464
True
Client Services
29
Benjamin
Male
2005-01-26
2017-05-17 22:06:00
79529
7.008
True
Legal
30
Christina
Female
2002-08-06
2017-05-17 13:19:00
118780
9.096
True
Engineering
32
NaN
Male
1998-08-21
2017-05-17 14:27:00
122340
6.417
True
NaN
33
Jean
Female
1993-12-18
2017-05-17 09:07:00
119082
16.180
False
Business Development
...
...
...
...
...
...
...
...
...
966
Louis
Male
2011-08-16
2017-05-17 17:19:00
93022
9.146
True
Human Resources
967
Thomas
Male
2016-03-12
2017-05-17 15:10:00
105681
19.572
False
Engineering
968
Louise
Female
1995-03-27
2017-05-17 22:27:00
43050
11.671
False
Distribution
969
Linda
Female
2010-02-04
2017-05-17 20:49:00
44486
17.308
True
Engineering
970
Alice
Female
1988-09-03
2017-05-17 20:54:00
63571
15.397
True
Product
971
Patrick
Male
2002-12-30
2017-05-17 02:01:00
75423
5.368
True
Business Development
973
Russell
Male
2013-05-10
2017-05-17 23:08:00
137359
11.105
False
Business Development
974
Harry
Male
2011-08-30
2017-05-17 18:31:00
67656
16.455
True
Client Services
975
Susan
Female
1995-04-07
2017-05-17 22:05:00
92436
12.467
False
Sales
976
Denise
Female
1992-10-19
2017-05-17 05:42:00
137954
4.195
True
Legal
977
Sarah
Female
1995-12-04
2017-05-17 09:16:00
124566
5.949
False
Product
978
Sean
Male
1983-01-17
2017-05-17 14:23:00
66146
11.178
False
Human Resources
979
Ernest
Male
2013-07-20
2017-05-17 06:41:00
142935
13.198
True
Product
980
Kimberly
Female
2013-01-26
2017-05-17 00:57:00
46233
8.862
True
Engineering
981
James
Male
1993-01-15
2017-05-17 17:19:00
148985
19.280
False
Legal
982
Rose
Female
1982-04-06
2017-05-17 10:43:00
91411
8.639
True
Human Resources
983
John
Male
1982-12-23
2017-05-17 22:35:00
146907
11.738
False
Engineering
984
Maria
Female
2011-10-15
2017-05-17 16:53:00
43455
13.040
False
Engineering
986
Donna
Female
1982-11-26
2017-05-17 07:04:00
82871
17.999
False
Marketing
987
Gloria
Female
2014-12-08
2017-05-17 05:08:00
136709
10.331
True
Finance
988
Alice
Female
2004-10-05
2017-05-17 09:34:00
47638
11.209
False
Human Resources
990
Robin
Female
1987-07-24
2017-05-17 13:35:00
100765
10.982
True
Client Services
991
Rose
Female
2002-08-25
2017-05-17 05:12:00
134505
11.051
True
Marketing
992
Anthony
Male
2011-10-16
2017-05-17 08:35:00
112769
11.625
True
Finance
993
Tina
Female
1997-05-15
2017-05-17 15:53:00
56450
19.040
True
Engineering
994
George
Male
2013-06-21
2017-05-17 17:47:00
98874
4.479
True
Marketing
996
Phillip
Male
1984-01-31
2017-05-17 06:30:00
42392
19.675
False
Finance
997
Russell
Male
2013-05-20
2017-05-17 12:39:00
96914
1.421
False
Product
998
Larry
Male
2013-04-20
2017-05-17 16:45:00
60500
11.985
False
Business Development
999
Albert
Male
2012-05-15
2017-05-17 18:24:00
129949
10.169
True
Sales
855 rows × 8 columns
In [104]:
df[df['Bonus %'].between(5, 7)]
Out[104]:
First Name
Gender
Start Date
Last Login Time
Salary
Bonus %
Senior Management
Team
0
Douglas
Male
1993-08-06
2017-05-17 12:42:00
97308
6.945
True
Marketing
13
Gary
Male
2008-01-27
2017-05-17 23:40:00
109831
5.831
False
Sales
17
Shawn
Male
1986-12-07
2017-05-17 19:45:00
111737
6.414
False
Product
23
NaN
Male
2012-06-14
2017-05-17 16:19:00
125792
5.042
True
NaN
27
Scott
NaN
1991-07-11
2017-05-17 18:58:00
122367
5.218
False
Legal
32
NaN
Male
1998-08-21
2017-05-17 14:27:00
122340
6.417
True
NaN
38
Stephanie
Female
1986-09-13
2017-05-17 01:52:00
36844
5.574
True
Business Development
43
Marilyn
Female
1980-12-07
2017-05-17 03:16:00
73524
5.207
True
Marketing
46
Bruce
Male
2009-11-28
2017-05-17 22:47:00
114796
6.796
False
Finance
48
Clarence
Male
1996-03-26
2017-05-17 05:57:00
93581
6.083
True
Business Development
70
Todd
NaN
2003-06-10
2017-05-17 14:26:00
84692
6.617
False
Client Services
75
Bonnie
Female
1991-07-02
2017-05-17 01:27:00
104897
5.118
True
Human Resources
78
Robin
Female
1983-06-04
2017-05-17 15:15:00
114797
5.965
True
Sales
83
Shawn
Male
2005-09-23
2017-05-17 02:55:00
148115
6.539
True
Finance
88
Donna
Female
1991-11-27
2017-05-17 13:59:00
64088
6.155
True
Legal
114
Ashley
Female
2002-08-04
2017-05-17 11:00:00
58698
6.811
True
Business Development
127
William
Male
2002-09-29
2017-05-17 16:09:00
66521
5.830
False
Human Resources
130
Shirley
Female
1984-05-01
2017-05-17 13:15:00
41334
6.219
True
Human Resources
138
Ashley
Female
2006-05-25
2017-05-17 11:30:00
112238
6.030
True
Engineering
142
Elizabeth
Female
2003-10-09
2017-05-17 17:53:00
146129
5.687
False
Finance
154
Rebecca
Female
1980-11-15
2017-05-17 04:13:00
85730
5.359
True
Product
169
Michelle
Female
1996-11-04
2017-05-17 21:34:00
53754
5.455
True
Product
174
NaN
NaN
2007-09-18
2017-05-17 18:59:00
40297
6.185
True
Client Services
180
Mark
Male
2008-04-12
2017-05-17 17:40:00
57286
5.025
True
Business Development
187
Roger
Male
2004-11-19
2017-05-17 15:55:00
51430
6.460
False
Marketing
191
Lois
Female
2013-10-18
2017-05-17 16:51:00
36946
6.652
False
Engineering
202
Roger
Male
1982-11-08
2017-05-17 02:32:00
140558
5.084
True
Sales
220
NaN
Female
1991-06-17
2017-05-17 12:49:00
71945
5.560
True
Marketing
238
Kevin
Male
1982-03-25
2017-05-17 07:31:00
35061
5.128
False
Legal
241
Walter
Male
1983-07-06
2017-05-17 23:54:00
127813
5.961
False
Finance
...
...
...
...
...
...
...
...
...
735
Barbara
Female
2002-11-26
2017-05-17 05:32:00
82884
6.837
True
Business Development
744
Judy
NaN
2011-07-15
2017-05-17 15:38:00
46829
5.190
True
Finance
753
Antonio
Male
1999-06-06
2017-05-17 22:54:00
41928
5.478
True
NaN
775
Rose
Female
1999-11-03
2017-05-17 09:06:00
75181
6.060
True
Finance
778
Antonio
Male
2003-12-28
2017-05-17 04:17:00
137979
5.266
False
Distribution
789
Lisa
Female
2000-07-08
2017-05-17 21:19:00
40121
6.293
False
Product
806
Kathryn
Female
2008-01-29
2017-05-17 00:29:00
86676
6.081
False
Sales
811
Judith
Female
1989-09-03
2017-05-17 11:16:00
134048
6.818
True
Marketing
812
NaN
Male
1994-12-13
2017-05-17 10:34:00
141311
5.478
True
Product
820
William
Male
1993-11-18
2017-05-17 12:27:00
54058
5.182
True
Human Resources
825
Robert
NaN
2000-12-04
2017-05-17 01:20:00
69267
5.890
True
Sales
826
NaN
NaN
1988-08-01
2017-05-17 01:35:00
87103
5.665
True
NaN
850
Charles
Male
1997-09-03
2017-05-17 10:04:00
148291
6.002
False
NaN
863
Phillip
Male
1984-05-15
2017-05-17 06:15:00
134120
6.842
False
Human Resources
864
Ryan
Male
2012-11-16
2017-05-17 13:47:00
57292
6.010
False
NaN
881
Ruby
Female
1980-01-28
2017-05-17 23:08:00
142868
6.318
False
Marketing
893
Frank
Male
2013-07-27
2017-05-17 16:32:00
91406
5.681
True
Business Development
901
Patricia
Female
1995-10-10
2017-05-17 16:52:00
119266
6.911
False
Distribution
902
NaN
Male
2001-05-23
2017-05-17 19:52:00
103877
6.322
True
Distribution
904
Stephanie
Female
1988-06-26
2017-05-17 05:48:00
136604
6.160
True
Human Resources
909
Donald
Male
1991-08-01
2017-05-17 02:25:00
61999
6.466
False
Product
913
Lois
Female
2015-12-11
2017-05-17 16:10:00
99747
6.168
False
Marketing
914
Ann
Female
2001-09-28
2017-05-17 06:37:00
71958
5.272
True
Distribution
915
Todd
Male
1983-01-04
2017-05-17 12:34:00
115566
6.716
True
Client Services
917
Shawn
Male
2008-03-13
2017-05-17 17:36:00
51667
6.339
False
Product
942
Lori
Female
2015-11-20
2017-05-17 13:15:00
75498
6.537
True
Marketing
947
NaN
Male
2012-07-30
2017-05-17 15:07:00
107351
5.329
True
Marketing
959
Albert
Male
1992-09-19
2017-05-17 02:35:00
45094
5.850
True
Business Development
971
Patrick
Male
2002-12-30
2017-05-17 02:01:00
75423
5.368
True
Business Development
977
Sarah
Female
1995-12-04
2017-05-17 09:16:00
124566
5.949
False
Product
109 rows × 8 columns
In [105]:
df[df['Start Date'].between('1980-01-01', '1980-01-31')]
Out[105]:
First Name
Gender
Start Date
Last Login Time
Salary
Bonus %
Senior Management
Team
49
Chris
NaN
1980-01-24
2017-05-17 12:13:00
113590
3.055
False
Sales
881
Ruby
Female
1980-01-28
2017-05-17 23:08:00
142868
6.318
False
Marketing
954
Joe
Male
1980-01-19
2017-05-17 16:06:00
119667
1.148
True
Finance
In [106]:
df[df['Last Login Time'].between('08:30AM', '09:30AM')]
Out[106]:
First Name
Gender
Start Date
Last Login Time
Salary
Bonus %
Senior Management
Team
10
Louise
Female
1980-08-12
2017-05-17 09:01:00
63241
15.132
True
NaN
33
Jean
Female
1993-12-18
2017-05-17 09:07:00
119082
16.180
False
Business Development
54
Sara
Female
2007-08-15
2017-05-17 09:23:00
83677
8.999
False
Engineering
85
Jeremy
Male
2008-02-01
2017-05-17 08:50:00
100238
3.887
True
Client Services
96
Cynthia
Female
1994-03-21
2017-05-17 08:34:00
142321
1.737
False
Finance
121
Kathleen
NaN
2016-05-09
2017-05-17 08:55:00
119735
18.740
False
Product
157
NaN
Female
2005-07-27
2017-05-17 08:32:00
79536
14.443
True
Product
161
Marilyn
NaN
1999-08-22
2017-05-17 09:09:00
103386
11.451
False
Distribution
259
Henry
Male
1995-02-06
2017-05-17 08:34:00
89258
15.585
True
Human Resources
321
Julie
Female
1986-03-23
2017-05-17 09:26:00
56926
7.507
False
Sales
345
Steven
Male
2006-11-21
2017-05-17 08:30:00
83706
6.960
True
Human Resources
352
NaN
Male
2011-10-09
2017-05-17 09:29:00
69906
4.844
True
Engineering
385
Debra
Female
2010-01-19
2017-05-17 08:48:00
70492
8.895
False
Client Services
391
Marilyn
Female
1989-08-15
2017-05-17 09:14:00
140502
9.989
True
Sales
397
Clarence
Male
2005-01-13
2017-05-17 09:00:00
116693
13.835
True
Distribution
399
Kathryn
Female
1988-06-09
2017-05-17 09:29:00
86439
7.799
False
Finance
429
Rose
Female
2015-05-28
2017-05-17 08:40:00
149903
5.630
False
Human Resources
446
Cheryl
Female
1994-08-16
2017-05-17 08:33:00
67150
15.850
True
Marketing
460
Tina
Female
2005-01-17
2017-05-17 09:11:00
88276
14.248
False
Legal
462
Craig
Male
1996-04-14
2017-05-17 09:17:00
125556
7.996
False
Engineering
463
Jose
Male
2002-07-11
2017-05-17 09:15:00
59862
3.269
False
Product
487
Cheryl
Female
2014-12-03
2017-05-17 09:27:00
71751
15.918
False
Business Development
520
Peter
Male
2003-02-22
2017-05-17 09:09:00
56580
8.411
True
NaN
530
Kathleen
Female
2014-06-13
2017-05-17 09:16:00
35575
14.595
False
Distribution
557
Jane
Female
1994-06-01
2017-05-17 08:39:00
42424
18.115
False
Distribution
605
Rose
Female
1982-05-20
2017-05-17 09:14:00
97691
2.142
False
Client Services
642
Amanda
NaN
2010-03-16
2017-05-17 09:17:00
135118
15.108
False
Finance
645
Anna
NaN
1985-03-13
2017-05-17 09:19:00
45418
10.162
False
Marketing
731
Ann
Female
2001-07-16
2017-05-17 09:27:00
118431
12.772
True
Finance
773
NaN
Male
1986-10-24
2017-05-17 09:23:00
47176
10.736
True
Finance
775
Rose
Female
1999-11-03
2017-05-17 09:06:00
75181
6.060
True
Finance
793
Andrea
Female
1999-07-22
2017-05-17 09:25:00
149105
13.707
True
Distribution
805
Thomas
Male
1990-05-03
2017-05-17 09:29:00
111371
15.081
True
Engineering
807
Mary
Female
2011-11-06
2017-05-17 08:32:00
115057
2.089
False
Finance
828
Cynthia
Female
2006-07-12
2017-05-17 08:55:00
149684
7.864
False
Product
840
Lillian
Female
2002-08-26
2017-05-17 08:53:00
103854
4.924
True
Distribution
852
Diana
Female
2004-11-19
2017-05-17 08:47:00
105066
17.343
True
Business Development
885
Juan
Male
1993-10-06
2017-05-17 08:52:00
85871
9.160
False
Product
887
David
Male
2009-12-05
2017-05-17 08:48:00
92242
15.407
False
Legal
906
Frances
Female
2014-05-16
2017-05-17 08:31:00
35884
17.667
False
Sales
922
Arthur
Male
2013-12-05
2017-05-17 08:44:00
86615
3.412
True
Business Development
932
Bonnie
Female
2008-12-23
2017-05-17 09:26:00
90427
2.010
True
Client Services
941
William
Male
1997-06-26
2017-05-17 08:33:00
104840
15.653
True
Engineering
977
Sarah
Female
1995-12-04
2017-05-17 09:16:00
124566
5.949
False
Product
992
Anthony
Male
2011-10-16
2017-05-17 08:35:00
112769
11.625
True
Finance
In [111]:
df[df['Last Login Time'].between('2017-05-17 ', '2017-05-18')]
Out[111]:
First Name
Gender
Start Date
Last Login Time
Salary
Bonus %
Senior Management
Team
0
Douglas
Male
1993-08-06
2017-05-17 12:42:00
97308
6.945
True
Marketing
1
Thomas
Male
1996-03-31
2017-05-17 06:53:00
61933
4.170
True
NaN
2
Maria
Female
1993-04-23
2017-05-17 11:17:00
130590
11.858
False
Finance
3
Jerry
Male
2005-03-04
2017-05-17 13:00:00
138705
9.340
True
Finance
4
Larry
Male
1998-01-24
2017-05-17 16:47:00
101004
1.389
True
Client Services
5
Dennis
Male
1987-04-18
2017-05-17 01:35:00
115163
10.125
False
Legal
6
Ruby
Female
1987-08-17
2017-05-17 16:20:00
65476
10.012
True
Product
7
NaN
Female
2015-07-20
2017-05-17 10:43:00
45906
11.598
True
Finance
8
Angela
Female
2005-11-22
2017-05-17 06:29:00
95570
18.523
True
Engineering
9
Frances
Female
2002-08-08
2017-05-17 06:51:00
139852
7.524
True
Business Development
10
Louise
Female
1980-08-12
2017-05-17 09:01:00
63241
15.132
True
NaN
11
Julie
Female
1997-10-26
2017-05-17 15:19:00
102508
12.637
True
Legal
12
Brandon
Male
1980-12-01
2017-05-17 01:08:00
112807
17.492
True
Human Resources
13
Gary
Male
2008-01-27
2017-05-17 23:40:00
109831
5.831
False
Sales
14
Kimberly
Female
1999-01-14
2017-05-17 07:13:00
41426
14.543
True
Finance
15
Lillian
Female
2016-06-05
2017-05-17 06:09:00
59414
1.256
False
Product
16
Jeremy
Male
2010-09-21
2017-05-17 05:56:00
90370
7.369
False
Human Resources
17
Shawn
Male
1986-12-07
2017-05-17 19:45:00
111737
6.414
False
Product
18
Diana
Female
1981-10-23
2017-05-17 10:27:00
132940
19.082
False
Client Services
19
Donna
Female
2010-07-22
2017-05-17 03:48:00
81014
1.894
False
Product
20
Lois
NaN
1995-04-22
2017-05-17 19:18:00
64714
4.934
True
Legal
21
Matthew
Male
1995-09-05
2017-05-17 02:12:00
100612
13.645
False
Marketing
22
Joshua
NaN
2012-03-08
2017-05-17 01:58:00
90816
18.816
True
Client Services
23
NaN
Male
2012-06-14
2017-05-17 16:19:00
125792
5.042
True
NaN
24
John
Male
1992-07-01
2017-05-17 22:08:00
97950
13.873
False
Client Services
25
NaN
Male
2012-10-08
2017-05-17 01:12:00
37076
18.576
True
Client Services
26
Craig
Male
2000-02-27
2017-05-17 07:45:00
37598
7.757
True
Marketing
27
Scott
NaN
1991-07-11
2017-05-17 18:58:00
122367
5.218
False
Legal
28
Terry
Male
1981-11-27
2017-05-17 18:30:00
124008
13.464
True
Client Services
29
Benjamin
Male
2005-01-26
2017-05-17 22:06:00
79529
7.008
True
Legal
...
...
...
...
...
...
...
...
...
970
Alice
Female
1988-09-03
2017-05-17 20:54:00
63571
15.397
True
Product
971
Patrick
Male
2002-12-30
2017-05-17 02:01:00
75423
5.368
True
Business Development
972
Victor
NaN
2006-07-28
2017-05-17 14:49:00
76381
11.159
True
Sales
973
Russell
Male
2013-05-10
2017-05-17 23:08:00
137359
11.105
False
Business Development
974
Harry
Male
2011-08-30
2017-05-17 18:31:00
67656
16.455
True
Client Services
975
Susan
Female
1995-04-07
2017-05-17 22:05:00
92436
12.467
False
Sales
976
Denise
Female
1992-10-19
2017-05-17 05:42:00
137954
4.195
True
Legal
977
Sarah
Female
1995-12-04
2017-05-17 09:16:00
124566
5.949
False
Product
978
Sean
Male
1983-01-17
2017-05-17 14:23:00
66146
11.178
False
Human Resources
979
Ernest
Male
2013-07-20
2017-05-17 06:41:00
142935
13.198
True
Product
980
Kimberly
Female
2013-01-26
2017-05-17 00:57:00
46233
8.862
True
Engineering
981
James
Male
1993-01-15
2017-05-17 17:19:00
148985
19.280
False
Legal
982
Rose
Female
1982-04-06
2017-05-17 10:43:00
91411
8.639
True
Human Resources
983
John
Male
1982-12-23
2017-05-17 22:35:00
146907
11.738
False
Engineering
984
Maria
Female
2011-10-15
2017-05-17 16:53:00
43455
13.040
False
Engineering
985
Stephen
NaN
1983-07-10
2017-05-17 20:10:00
85668
1.909
False
Legal
986
Donna
Female
1982-11-26
2017-05-17 07:04:00
82871
17.999
False
Marketing
987
Gloria
Female
2014-12-08
2017-05-17 05:08:00
136709
10.331
True
Finance
988
Alice
Female
2004-10-05
2017-05-17 09:34:00
47638
11.209
False
Human Resources
989
Justin
NaN
1991-02-10
2017-05-17 16:58:00
38344
3.794
False
Legal
990
Robin
Female
1987-07-24
2017-05-17 13:35:00
100765
10.982
True
Client Services
991
Rose
Female
2002-08-25
2017-05-17 05:12:00
134505
11.051
True
Marketing
992
Anthony
Male
2011-10-16
2017-05-17 08:35:00
112769
11.625
True
Finance
993
Tina
Female
1997-05-15
2017-05-17 15:53:00
56450
19.040
True
Engineering
994
George
Male
2013-06-21
2017-05-17 17:47:00
98874
4.479
True
Marketing
995
Henry
NaN
2014-11-23
2017-05-17 06:09:00
132483
16.655
False
Distribution
996
Phillip
Male
1984-01-31
2017-05-17 06:30:00
42392
19.675
False
Finance
997
Russell
Male
2013-05-20
2017-05-17 12:39:00
96914
1.421
False
Product
998
Larry
Male
2013-04-20
2017-05-17 16:45:00
60500
11.985
False
Business Development
999
Albert
Male
2012-05-15
2017-05-17 18:24:00
129949
10.169
True
Sales
1000 rows × 8 columns
In [113]:
df = pd.read_csv('data/employees.csv', parse_dates=['Start Date', 'Last Login Time'])
df['Gender'] = df['Gender'].astype('category')
df['Team'] = df['Team'].astype('category')
df['Senior Management'] = df['Senior Management'].astype('bool')
df.sort_values('First Name', inplace=True)
df.head(3)
Out[113]:
First Name
Gender
Start Date
Last Login Time
Salary
Bonus %
Senior Management
Team
101
Aaron
Male
2012-02-17
2017-05-17 10:20:00
61602
11.849
True
Marketing
327
Aaron
Male
1994-01-29
2017-05-17 18:48:00
58755
5.097
True
Marketing
440
Aaron
Male
1990-07-22
2017-05-17 14:53:00
52119
11.343
True
Client Services
In [134]:
df['First Name'].duplicated()
Out[134]:
101 False
327 True
440 True
937 True
137 False
141 True
302 True
538 True
300 False
53 True
610 True
372 False
458 True
477 True
680 True
999 True
959 True
988 False
970 True
765 True
425 True
905 True
684 True
935 True
693 True
639 False
642 True
578 True
553 True
542 True
...
567 True
574 True
599 True
607 True
608 True
626 True
628 True
674 True
685 True
687 True
697 True
709 True
733 True
734 True
773 True
774 True
782 True
783 True
785 True
812 True
821 True
823 True
826 True
877 True
890 True
902 True
925 True
946 True
947 True
951 True
Name: First Name, Length: 1000, dtype: bool
In [128]:
# Delete Duplicate values
df['First Name'].duplicated(keep=False)
Out[128]:
101 True
327 True
440 True
937 True
137 True
141 True
302 True
538 True
300 True
53 True
610 True
372 True
458 True
477 True
680 True
999 True
959 True
988 True
970 True
765 True
425 True
905 True
684 True
935 True
693 True
639 True
642 True
578 True
553 True
542 True
...
567 True
574 True
599 True
607 True
608 True
626 True
628 True
674 True
685 True
687 True
697 True
709 True
733 True
734 True
773 True
774 True
782 True
783 True
785 True
812 True
821 True
823 True
826 True
877 True
890 True
902 True
925 True
946 True
947 True
951 True
Name: First Name, Length: 1000, dtype: bool
In [131]:
mask = -df['First Name'].duplicated(keep=False)
In [132]:
df[mask]
Out[132]:
First Name
Gender
Start Date
Last Login Time
Salary
Bonus %
Senior Management
Team
8
Angela
Female
2005-11-22
2017-05-17 06:29:00
95570
18.523
True
Engineering
688
Brian
Male
2007-04-07
2017-05-17 22:47:00
93901
17.821
True
Legal
190
Carol
Female
1996-03-19
2017-05-17 03:39:00
57783
9.129
False
Finance
887
David
Male
2009-12-05
2017-05-17 08:48:00
92242
15.407
False
Legal
5
Dennis
Male
1987-04-18
2017-05-17 01:35:00
115163
10.125
False
Legal
495
Eugene
Male
1984-05-24
2017-05-17 10:54:00
81077
2.117
False
Sales
33
Jean
Female
1993-12-18
2017-05-17 09:07:00
119082
16.180
False
Business Development
832
Keith
Male
2003-02-12
2017-05-17 15:02:00
120672
19.467
False
Legal
291
Tammy
Female
1984-11-11
2017-05-17 10:30:00
132839
17.463
True
Client Services
In [152]:
# Keep first occurence
df.drop_duplicates(subset=['First Name'])
Out[152]:
First Name
Gender
Start Date
Last Login Time
Salary
Bonus %
Senior Management
Team
101
Aaron
Male
2012-02-17
2017-05-17 10:20:00
61602
11.849
True
Marketing
137
Adam
Male
2011-05-21
2017-05-17 01:45:00
95327
15.120
False
Distribution
300
Alan
Male
1988-06-26
2017-05-17 03:54:00
111786
3.592
True
Engineering
372
Albert
Male
1997-02-01
2017-05-17 16:20:00
67827
19.717
True
Engineering
988
Alice
Female
2004-10-05
2017-05-17 09:34:00
47638
11.209
False
Human Resources
639
Amanda
NaN
1991-08-11
2017-05-17 14:15:00
46665
19.391
True
Client Services
879
Amy
Female
2009-05-20
2017-05-17 06:26:00
75415
19.132
False
Client Services
430
Andrea
Female
2010-10-01
2017-05-17 11:54:00
79123
19.422
False
Distribution
564
Andrew
Male
1985-03-29
2017-05-17 18:57:00
43414
7.563
True
Client Services
8
Angela
Female
2005-11-22
2017-05-17 06:29:00
95570
18.523
True
Engineering
509
Ann
Female
1984-11-04
2017-05-17 12:17:00
90719
6.220
False
Business Development
645
Anna
NaN
1985-03-13
2017-05-17 09:19:00
45418
10.162
False
Marketing
262
Anne
Female
1986-07-16
2017-05-17 14:08:00
69134
3.723
True
Engineering
87
Annie
Female
1993-01-30
2017-05-17 02:05:00
144887
8.276
True
Sales
886
Anthony
Male
2014-01-30
2017-05-17 21:04:00
96795
14.837
False
Sales
129
Antonio
Male
1988-10-25
2017-05-17 13:50:00
60866
13.101
True
Business Development
556
Arthur
Male
2014-12-16
2017-05-17 16:56:00
66819
6.639
True
Marketing
138
Ashley
Female
2006-05-25
2017-05-17 11:30:00
112238
6.030
True
Engineering
735
Barbara
Female
2002-11-26
2017-05-17 05:32:00
82884
6.837
True
Business Development
757
Benjamin
Male
1988-04-12
2017-05-17 23:32:00
123409
7.783
False
Product
894
Betty
Female
2002-11-19
2017-05-17 10:40:00
37005
7.645
True
Marketing
956
Beverly
Female
1986-10-17
2017-05-17 00:51:00
80838
8.115
False
Engineering
838
Billy
Male
2000-04-06
2017-05-17 15:14:00
115280
9.153
False
Distribution
776
Bobby
Male
2004-09-30
2017-05-17 22:52:00
79047
18.784
False
Human Resources
79
Bonnie
Female
1988-11-13
2017-05-17 15:30:00
115814
4.990
False
Product
892
Brandon
Male
1995-10-23
2017-05-17 12:04:00
60263
2.709
False
Sales
872
Brenda
Female
2015-01-18
2017-05-17 16:39:00
73749
19.332
False
Business Development
688
Brian
Male
2007-04-07
2017-05-17 22:47:00
93901
17.821
True
Legal
604
Bruce
Male
2013-03-15
2017-05-17 23:13:00
141335
15.427
True
Engineering
282
Carl
NaN
2014-02-07
2017-05-17 03:57:00
125104
12.345
False
Client Services
...
...
...
...
...
...
...
...
...
696
Samuel
Male
2012-05-25
2017-05-17 16:40:00
85550
11.593
True
Marketing
589
Sandra
Female
1995-04-24
2017-05-17 19:14:00
116931
9.657
True
Human Resources
882
Sara
NaN
2014-11-18
2017-05-17 14:47:00
135990
14.344
True
Distribution
417
Sarah
NaN
1981-08-31
2017-05-17 14:51:00
37748
9.047
False
Human Resources
452
Scott
Male
2012-11-17
2017-05-17 14:47:00
146812
1.965
True
Marketing
501
Sean
Male
2013-02-11
2017-05-17 19:07:00
42748
9.765
False
Distribution
489
Sharon
Female
2011-07-01
2017-05-17 09:50:00
46007
19.731
True
Client Services
804
Shawn
Male
2008-03-17
2017-05-17 14:12:00
39335
10.664
False
Distribution
130
Shirley
Female
1984-05-01
2017-05-17 13:15:00
41334
6.219
True
Human Resources
475
Stephanie
Female
1992-11-26
2017-05-17 00:54:00
122121
7.937
True
Engineering
756
Stephen
Male
1984-10-21
2017-05-17 06:26:00
121816
10.615
True
Distribution
525
Steve
Male
1995-08-22
2017-05-17 06:58:00
67780
9.540
True
Human Resources
743
Steven
Male
1980-05-30
2017-05-17 20:25:00
100949
13.813
True
Human Resources
975
Susan
Female
1995-04-07
2017-05-17 22:05:00
92436
12.467
False
Sales
291
Tammy
Female
1984-11-11
2017-05-17 10:30:00
132839
17.463
True
Client Services
613
Teresa
NaN
1992-01-03
2017-05-17 15:47:00
63103
11.378
False
Finance
762
Terry
Male
2004-11-10
2017-05-17 04:33:00
35633
3.947
True
Distribution
795
Theresa
NaN
1995-10-07
2017-05-17 10:16:00
42025
3.319
True
Human Resources
967
Thomas
Male
2016-03-12
2017-05-17 15:10:00
105681
19.572
False
Engineering
664
Timothy
Male
2010-10-06
2017-05-17 22:49:00
49473
12.463
False
Legal
113
Tina
Female
2009-06-12
2017-05-17 07:16:00
114767
3.711
True
Engineering
609
Todd
Male
2010-02-16
2017-05-17 11:29:00
103405
15.910
False
Sales
422
Victor
Male
2005-09-24
2017-05-17 12:04:00
123144
16.261
True
Product
294
Virginia
Female
1999-10-20
2017-05-17 06:23:00
46905
19.154
False
Distribution
288
Walter
NaN
1999-12-21
2017-05-17 22:33:00
66757
18.099
False
Distribution
433
Wanda
Female
2008-07-20
2017-05-17 13:44:00
65362
7.132
True
Legal
177
Wayne
Male
2012-04-07
2017-05-17 08:00:00
102652
14.085
True
Distribution
820
William
Male
1993-11-18
2017-05-17 12:27:00
54058
5.182
True
Human Resources
450
Willie
Male
2009-08-22
2017-05-17 13:03:00
55038
19.691
False
Legal
7
NaN
Female
2015-07-20
2017-05-17 10:43:00
45906
11.598
True
Finance
201 rows × 8 columns
In [150]:
# Drop if is duplicate
df.drop_duplicates(subset=['First Name'], keep=False)
Out[150]:
First Name
Gender
Start Date
Last Login Time
Salary
Bonus %
Senior Management
Team
8
Angela
Female
2005-11-22
2017-05-17 06:29:00
95570
18.523
True
Engineering
688
Brian
Male
2007-04-07
2017-05-17 22:47:00
93901
17.821
True
Legal
190
Carol
Female
1996-03-19
2017-05-17 03:39:00
57783
9.129
False
Finance
887
David
Male
2009-12-05
2017-05-17 08:48:00
92242
15.407
False
Legal
5
Dennis
Male
1987-04-18
2017-05-17 01:35:00
115163
10.125
False
Legal
495
Eugene
Male
1984-05-24
2017-05-17 10:54:00
81077
2.117
False
Sales
33
Jean
Female
1993-12-18
2017-05-17 09:07:00
119082
16.180
False
Business Development
832
Keith
Male
2003-02-12
2017-05-17 15:02:00
120672
19.467
False
Legal
291
Tammy
Female
1984-11-11
2017-05-17 10:30:00
132839
17.463
True
Client Services
In [157]:
df.drop_duplicates(subset=['First Name', 'Team'], keep=False, inplace=True)
In [158]:
df.head(3)
Out[158]:
First Name
Gender
Start Date
Last Login Time
Salary
Bonus %
Senior Management
Team
137
Adam
Male
2011-05-21
2017-05-17 01:45:00
95327
15.120
False
Distribution
141
Adam
Male
1990-12-24
2017-05-17 20:57:00
110194
14.727
True
Product
300
Alan
Male
1988-06-26
2017-05-17 03:54:00
111786
3.592
True
Engineering
In [159]:
len(df)
Out[159]:
606
In [160]:
df = pd.read_csv('data/employees.csv', parse_dates=['Start Date', 'Last Login Time'])
df['Gender'] = df['Gender'].astype('category')
df['Team'] = df['Team'].astype('category')
df['Senior Management'] = df['Senior Management'].astype('bool')
df.sort_values('First Name', inplace=True)
df.head(3)
Out[160]:
First Name
Gender
Start Date
Last Login Time
Salary
Bonus %
Senior Management
Team
101
Aaron
Male
2012-02-17
2017-05-17 10:20:00
61602
11.849
True
Marketing
327
Aaron
Male
1994-01-29
2017-05-17 18:48:00
58755
5.097
True
Marketing
440
Aaron
Male
1990-07-22
2017-05-17 14:53:00
52119
11.343
True
Client Services
In [161]:
df['Gender'].unique()
Out[161]:
[Male, NaN, Female]
Categories (2, object): [Male, Female]
In [162]:
df['Team'].unique()
Out[162]:
[Marketing, Client Services, Distribution, Product, Human Resources, ..., Finance, Business Development, Sales, NaN, Legal]
Length: 11
Categories (10, object): [Marketing, Client Services, Distribution, Product, ..., Finance, Business Development, Sales, Legal]
In [169]:
# is not counting NaN values
df['Team'].nunique(dropna=False), df['Team'].nunique()
Out[169]:
(11, 10)
In [168]:
len(df['Team'].unique())
Out[168]:
11
In [ ]:
Content source: topix-hackademy/pandas-for-dummies
Similar notebooks: