CHALLENGE QUESTION
Imagine you’re a data analyst and you’ve just been handed a set of data that shows the number of accidents for all drivers, their ages, and the size of their engines. You need to figure out a way to display this information so that it tells a story. Normally you would create a graph with x, y, z coordinates; however, that can become complicated, and you don’t have time for that. How would you render the information so that it’s still considered 3-dimensional, but you can only use the x and y axis?
Monday: Virtual Environments and Requests Module
Today we’ll be learning all about virtual environments, why we need them and how to use them. They’re necessary for what we need to do this week, which is downloading and importing a few libraries to work with. We’ll also get into the requests module and cover APIs briefly.
For today’s lesson, we won’t be starting out in Jupyter Notebook; instead open the terminal and cd into the “python_bootcamp” folder if you haven’t already. If you have the terminal running Jupyter Notebook, be sure to stop it, as we need to write some commands in the terminal.
What Are Virtual Environments?
Python virtual environments are essentially a tool that allows you to keep project dependencies in a separate space from other projects. Most projects in Python need to use modules that are not included by default with Python. Now, you could simply download the modules (or libraries) into your Python folder to use; however, that could cause some issues down the road. Let’s say you’re working on two separate projects, where the first one uses Python version 2.7 and the second project uses Python version 3.5. If you try and use the same syntax for both, you’ll run into several issues. Instead, you would create two separate virtual environments, one for each project. This way both projects can run properly using the correct dependencies because of the personalized virtual environment.
CHapter 10 INtroduCtIoN to data aNalYsIs
Note When creating a virtual environment, a folder called “venv” will appear. this is where all the libraries that you download are saved. simply put, a virtual environment is not much more than a folder that stores other files.
As an analogy to understand virtual environments, first picture our own planet. Now think of it as an environment filled with grass, sun, clouds, air, etc. In the case of programming, Python would be like the planet, and the grass, sun, clouds, and air would be like libraries that you need to include in the environment. As Python does not come included with them, we would create a virtual environment to store these libraries so that we may import them into our project when needed. If you think of Mars, that would be another project, with a separate virtual environment specifically made for that program.
Virtual environments can often be a tough concept to grasp for anyone seeing it for the first time, so here’s another analogy. Imagine you’ve planned two vacations, one to the beach and the other to go skiing. Rather than using the same suitcase filled with mixed clothes, you’ve decided to pack two separate suitcases. The one for the beach will include a bathing suit, sunglasses, and flip-flops. The other suitcase will include a jacket, skiis, and boots. In the following, you can find the relationships within this analogy:
Vacations ➤ Projects
Suitcases ➤ Virtual Environments
Clothes and Accessories ➤ Project Dependencies/Files
Do'stlaringiz bilan baham: |