Chọn hàng bằng logic

Nhập môn Khoa học Dữ liệu với Python

Hillary Green-Lerman

Lead Data Scientist, Looker

Tiếp tục điều tra

print(credit_records.head())
            suspect         location              date         item  price
0    Kirstine Smith   Groceries R Us   January 6, 2018     broccoli   1.25
1      Gertrude Cox  Petroleum Plaza   January 6, 2018  fizzy drink   1.90
2  Fred Frequentist   Groceries R Us   January 6, 2018     broccoli   1.25
3      Gertrude Cox   Groceries R Us  January 12, 2018     broccoli   1.25
4    Kirstine Smith    Clothing Club   January 9, 2018        shirt  14.25
Nhập môn Khoa học Dữ liệu với Python

Mệnh đề logic trong Python

question = 12 * 8
solution = 96
question == solution
True

Boolean: TrueFalse

Nhập môn Khoa học Dữ liệu với Python

Các dạng logic khác

, >=, <, <=

price = 2.25
price > 5.00
False

Khác

name = 'bayes'
name != 'Bayes'
True
Nhập môn Khoa học Dữ liệu với Python

Dùng logic với DataFrame

credit_records.price > 20.00
0      False
1      False
2      False
3      False
4       True
5      False
...
99      True
100     True
101     True
102    False
103    False
Nhập môn Khoa học Dữ liệu với Python

Dùng logic với DataFrame

credit_records[credit_records.price > 20.00]
                  suspect         location              date   item  price
28       Fred Frequentist    Clothing Club   January 3, 2018  dress  20.15
29         Kirstine Smith    Clothing Club   January 5, 2018  dress  20.15
33   Ronald Aylmer Fisher  Petroleum Plaza   January 7, 2018    gas  24.95
37       Fred Frequentist    Clothing Club   January 8, 2018  dress  20.15
40           Gertrude Cox    Clothing Club   January 1, 2018  dress  20.15
41         Kirstine Smith  Petroleum Plaza   January 5, 2018    gas  24.95
...
Nhập môn Khoa học Dữ liệu với Python

Dùng logic với DataFrame

Nhập môn Khoa học Dữ liệu với Python

Dùng logic với DataFrame

credit_records[credit_records.suspect == 'Ronald Aylmer Fisher']
                  suspect         location              date         item  price
7    Ronald Aylmer Fisher    Clothing Club   January 8, 2018        pants  12.05
8    Ronald Aylmer Fisher    Clothing Club  January 13, 2018        shirt  14.25
12   Ronald Aylmer Fisher  Petroleum Plaza  January 10, 2018      carwash  13.25
22   Ronald Aylmer Fisher   Groceries R Us  January 13, 2018         eggs   6.50
26   Ronald Aylmer Fisher      Burger Mart   January 8, 2018        fries   1.95
...
Nhập môn Khoa học Dữ liệu với Python

Ayo berlatih!

Nhập môn Khoa học Dữ liệu với Python

Preparing Video For Download...