Introduction to Python 1.2

This notebook is the continuation of the previous one and covers the usage of libraries in Python. While some functions are built-in with Python, others do not come preinstalled, so the user have to develop them. To save our time, some people have already developed useful functions and packaged the mtogether in different libraries for us to use for free. To use this libraries one just needs to install them (first) and import them into the Jupyter Notebook (second).

  • Installation - to isntall a library one needs to open a completely new Commpand Prompt (or Anaconda Prompt or Terminal) window and run the following command there: pip install library_name. pip tells command promptthat we will implement some Python stuff, install tells that we gone have installation procedure, and library_name should be replaced with the name of the library you want to install. When downloding and installing Anaconda some important libraries have already been installed in your computers. Yet some others that we will use should be manually installed by the user.

  • Import - once the library is installed one can import it into Jupyter Notebook by using the import keyword as follows: import numpy. Once library is imported, one can already use the functions residing in a library. Yet, everytime you use function from a library you have to provide the library name also. For example, to use the natural logarithm function from the numpy library one have to call numpy.log(). As you may have already understood, long library names can become a real headache. Fortunately, Python provides the opportunity to rename libraries only for the current Jupyter Notebook. To do that one should use the following approach: import numpy as np. Now, whenever you want to use a function from numpy library you can call it just np: np.log().

Libraries covered

  • numpy - stands for "numerical python", as the library includes powerful and popular mathematical functions.

  • pandas_datareader - provides opportunity to easilty get stock data from google finance.

Additional functions/types covered

Once a library is used, one may end up with a data type, which was not provided by Python itself but exists due to the imported library. As a result, there can be functions that can be implemented explicitely on this data types. Once pandas_datareader is used to get stock data, the data is received inside a type called "dataframe". Once you have a dataframe there are several dataframe functions that you can implement. We covered the following:

  • head() - presents the very first 5 observatinos of the dataframe,

  • describe() - provides the descriptive statistics of the dataframe.