Using conventions in Python?
How to use conventions in Python?
An example of a convention is calling the web data web or wb . In our course, we obviously stick to the second one.
But in terms of Python code, what does wb refer to? It refers to the data part of the pandas-datareader package, right?That's why we begin our code with
from pandas_datareader import data as wb .
Having executed this line of code in your session (“session” meaning the period in which you will keep your notebook and Jupyter open), Python will know that wb refers to the data part of the pandas-datareader package. This is nothing but a large chunk of code where certain functions and methods have been specified.
Therefore, wb.DataReader() is simply an indication where Python should search for a method called
Other conventions are plt for pyplot matplotlib code, np for numpy, and pd for pandas. It is a sign of good practice to stick to conventions such as np , plt , wb . That's why we use them in the course and advise you to use them, too.
Note: Methods, on the other hand, have their fixed names, and you cannot really use an alias for them. You'd have to create a new function or method, based on the initial method, and give it a name you like. However, this is not something people normally do. Therefore, it is better to try to remember the method or function name you need.