Frequently Asked Question

Video: 6.2.1 Introduction to Python packages
Last Updated 3 years ago


Press "Ctrl + F" to find the keyword of your interest.

If you wish to have a direct link access to the video timestamps, please follow these instructions.

Found this video helpful? Why not take the whole HIL Specialist course? A Certificate is waiting for you for free at HIL Academy.

Would you or your organization benefit from having these videos narrated in your native language? Contact us and let us know if you wish to contribute.

TRANSCRIPT

00:00:02

Hello and welcome. In the Python Basics lesson, we covered the basics of what you need to know  

00:00:07

in Python to get started with test automation programming. In this lesson, we will look at  

00:00:12

some of the important publicly available Python packages that will help us do this. 

00:00:17

As mentioned in the last lesson, we are using PyCharm to write and execute Python Code.  

00:00:23

A guide for how to set up your PyCharm environment is also available in the Materials tab. 

00:00:28

Since Python is an open-source programming language, many people and companies have  

00:00:33

developed publicly available function libraries for it, called packages. Here, let s take a  

00:00:38

look of some very common packages, that come by default with Python installation, which optimize  

00:00:44

mathematical operations and data handling and come by default with each Python installation.  

00:00:49

These are numpy , pandas , and math .If your Python does not have these libraries  

00:00:55

installed, you can do so by running the 'pip install' command. 'pip' is  

00:00:59

a package-management system written in Python used to install and manage software packages.  

00:01:05

It connects to an online repository of public packages, called the Python Package Index. To  

00:01:11

check which libraries are installed, open the Pycharm terminal and type 'pip list'. 

00:01:19

To install a new library, use the 'pip install' command followed by the library name. 

00:01:30

As you can see, some libraries like pandas have dependencies on other libraries,  

00:01:35

and these are installed automatically.There are multiple ways to import  

00:01:42

a package. The easiest is to simply import the whole library as shown here.

00:01:47

Once math is imported, you can access all its functions and methods by using  

00:01:51

math.<function or attribute> . In Pycharm, after importing the package,  

00:01:56

you can type math. to check all the available functions in the popup screen. 

00:02:06

An alternative is to import specific functions from a library.  

00:02:10

This lets you avoid having to type the entire package name each time you use one of its methods.

00:02:24

A third way to import, is by using an alias with as .

00:02:28

This gives the package a shorter name, making the code more readable. 

00:02:33

Now let s take a look at the pandas library. This is a great library for manipulating large  

00:02:38

amounts of data and is used by the Typhoon HIL toolchain to return captured results.  

00:02:43

The package also helps to organize and extract information from data using the datatype called  

00:02:48

dataframe which is a 2-dimensional table of rows and columns similar to a spreadsheet. 

00:02:53

Let s start by creating a dataframe like the one returned by Typhoon s capture.

00:03:22

When we print a Dataframe, we can see its structure, consisting of 4 columns. The  

00:03:28

first is called an index, and it is used to identify the lines of the Dataframe.  

00:03:32

The rest of the columns, are the data for three-phase signals.  

00:03:36

To better visualize the signal, we can plot them using the .plot() method.

00:03:49

It is possible to select columns of the dataframe, except the index,  

00:03:54

by specifying them between [] . If you wish to select multiple columns, provide them as a list. 

00:04:12

To access the index, we can use df.index . 

00:04:21

We can slice the dataframe, selecting specific time intervals.  

00:04:25

If you use integer numbers, it will slice considering samples. 

00:04:32

You can also slice using time deltas. For example,  

00:04:35

here we slice a dataframe to plot one fundamental cycle.

00:05:00

Pandas has a very powerful set of functions to extract information and manipulate data.  

00:05:06

For example, to obtain the maximum, minimum, and average values for each one of the series,  

00:05:11

you only need to use the .max() , .min() , and .mean() methods.

00:05:19

You can find many other functions in the pandas documentation or by searching the web.  

00:05:24

This is all for the Python basics lessons. In the next lessons,  

00:05:28

you will learn how to use Pytest, a very powerful Python testing framework.

00:05:33

Thank you for watching!

Please Wait!

Please wait... it will take a second!