EME 210
Data Analytics for Energy Systems

Python Coding Fundamentals: Libraries

PrintPrint

Libraries
 

In Python, a “library” is a collection of code, including functions, classes, and variables, among other things. The way that Python works is that you have different libraries that contain different sets of functions, and you use the functions in any given library once you load the library into your session. There are some base functions within Python that you can use without loading any libraries, but a lot of the more complex data analysis tasks in this class are going to require the use of libraries. Each library in Python has a documentation website, and each library's documentation will be in a similar format to other libraries. The links below take you to the documentation for most of the libraries we'll use in this course, and subsequent lessons will instruct you on the use of many of the functions contained in these libraries. Most of the libraries will have something called examples or tutorials. Some libraries may also have galleries. But, essentially, these documentation sites will have resources that you can use to build if you need an example or need to figure out how something works or even just to figure out how to customize something or see what the options are for a certain command. 

The main libraries used in this course are:

NumPy | NumPy User Guide

NumPy is a very popular and almost necessary library within Python called NumPy.  This library is used to do mathematics with arrays, vectors and other numerical routines. If you wanted to calculate 2 + 2, for example, you could do that in Python. But if you want to do an array, 2, 2, + another array, 4, 4, and get ultimately what would be 6, 6, you need the NumPy array to do that more complex math.

Pandas | Pandas User Guide

Another package that we'll be using quite a bit in this class is called Pandas. And this is really great fto use when working with complex data sets. Pandas it works with something that we'll discuss later called a DataFrame, which is akin to a table in Excel.  In fact, a lot of the functionality of Pandas is similar to that of Excel. You can call with columns. You can call rows. You can do complex math. You can sort, filter, et cetera. 

Matplotlib | Matplotlb User Guide

Matplotlib is a very popular package used for visualizing data and making plots, and uses MATLAB-like syntax.

Seaborn | Seaboorn User Guide

Seaborn is a more advanced plotting tool that's used in a lot of statistical purposes, but can be a little bit rigid in some cases when you try to add different elements to the plot. 

Plotnine | Plotnine User Guide.

Plotnine is what is referred to as the Grammar of Graphics visualization library. This means that it operates similar to how one would construct a sentence, adding prepositions and additional verbs and nouns. For example, in a sentence, you could start with "The quick...". Then, if you wanted to extend the sentence, you could say "The quick brown fox...". You could go further and add a verb: "The quick brown fox jumps...", and so forth, continuing to add on words that ultimately keep extending the sentence with new information. Plotnine works in a similar way where, for example, one starts with a bar plot, and then adds error bars, and then text labels, and so on, building complex plots from individual elements. 

Because Python is open source, there are a lot of opportunities online to find snippets of code. You are more than welcome to find an example that's close to what you're trying to do, and then modify it to work for your intended purpose. That's often how a lot of code gets built, especially at the beginning when trying to figure out how different functions operate and how to accomplish certain tasks in Python.

  Take a Minute

Take a minute to explore the links to the libraries listed above.