To show you why Numpy and pandas are useful.
I'm going to revisit some code from last lesson, and
see how it would look if I wrote it using pandas.
This is the code to first take a CSV and read it into a list, and
then get the unique accounts out of that list.
I'm running this code on the daily engagement full file,
since that file is rather large, and pandas deals with large files nicely.
Now if I run the code to load the file into a CSV, it takes a little while and
finally it finished.
Now, we cut some of the loading time out of the video, but
it took about one minute.
Then after that, getting the unique students takes a little while as well.
In fact, this one is going to take about six seconds, and now we're done.
As you'll see in a minute, when I use pandas,
the code will run much more quickly.
In fact, in pandas this will also be only three lines of code.
The first will be this import statement.
In the second, I'll read it in the file using pandas built-in read CSV function.
And, finally, I can specify that I want to look at the acct column.
And then use pandas built-in unique function to get the unique accounts.
As you can see, pandas has a lot of convenient functions, like read CSV and
unique, that previously we had written ourselves.
Now of these three lines of code, the one that actually takes the longest for
me is importing pandas, which takes several seconds the first time I do it.
That is certainly very long for just importing a library.
But it more than makes up for it with the speed of the rest of the code.
After that, reading the data into the CSV takes just a few seconds,
rather than the one minute that I waited earlier.
And actually getting the unique accounts finishes before I can even blink.