From the course: Testing Python Data Science Code
Unlock this course with a free trial
Join today to access over 25,500 courses taught by industry experts.
Comparing pandas DataFrames - Python Tutorial
From the course: Testing Python Data Science Code
Comparing pandas DataFrames
- [Teacher] Let's say you have some code checking for fraud data. Here's a simplified version of the code, just for testing. We have the output, with the idea of the transaction, and then confidence if it's fraud or not. And then we have the expected output, from the model. And we are going to do assert out equal expected. Let's run the test. And we're going to see that the true value of a data frame is ambiguous. We use empty, Boolean, et cetera, et cetera. And again, here we need to compare. We can iterate over the columns and use numpy or close but pandas itself also have testing utilities. So we have testing assert frame equal. If you look at it, there are several parameters. It gets left and right to compare and then check data types, check indexing, et cetera, et cetera, and also relative and absolute tolerance. Let's get back to our code and use this function. So from pandas, the testing import assert frame equal…
Contents
-
-
-
-
-
-
Using schemas2m 51s
-
(Locked)
Truth values2m 35s
-
(Locked)
Floating point wonders1m 46s
-
(Locked)
Approximate testing1m 18s
-
(Locked)
Dealing with randomness1m 45s
-
(Locked)
Comparing pandas DataFrames1m 31s
-
(Locked)
Challenge: Testing numerical code56s
-
(Locked)
Solution: Testing numerical code51s
-
-
-
-