YTread Logo
YTread Logo

Introduction to Python with Anaconda for Beginners

Feb 22, 2020
welcome to the

introduction

to Python with

anaconda

for

beginners

my name is Matias and I will do my best to get your style with Python programming in this video I will explain to you what Python is and what it is used for then I will explain what

anaconda

is and We'll show you how to install it, then go over some basic Python commands and syntax. I'll also show you how to run your program from the command line and at the end I'll show you some examples of advanced features. Perl Python Programs to Recap I'll point you to some resources you can use if you want to dive deeper into Python, let's get started.
introduction to python with anaconda for beginners
Python is a general purpose programming language that can be easily used for both small projects and large enterprise applications, it is best suited for web development, simple scripting and data analysis, but its flexibility allows it to be used for much more like web scraping game development, machine learning, browser automation, and internal stuff. Python is able to do all of this primarily thanks to all the various packages that extend its core functionality and that the Python beta community continually contributes to. Packages also known as libraries or modules. Our code collections that serve a particular purpose and help you speed up your development process.
introduction to python with anaconda for beginners

More Interesting Facts About,

introduction to python with anaconda for beginners...

An example of a package. can be random, allowing you to generate random numbers. Python is also very easy to learn and understand. Before we start coding in Python, we'll quickly go over anaconda, which is a Python distribution that comes loaded with hundreds of packages that are especially useful if you are planning to use Python for data science and machine learning. anaconda is still extremely useful even if you don't plan on use Python for data science because it comes with the Conda man package and a virtual environment manager and makes it extremely easy to work on multiple projects at the same time, all this means that anaconda makes developing with Python fast and eliminates all the headaches of tracking down package dependencies unless you are an experienced programmer.
introduction to python with anaconda for beginners
I highly recommend using anaconda as it allows you to skip setting up coding environments and allows you to jump straight to the interesting part of coding, if you are an experienced programmer this tutorial may not be very beneficial for you in the first place. I hope I was able to convince you that it will be worth giving up some of your valuable computer storage by installing Anaconda, if so. We will install anaconda by going to www.eddecosta.com slash distribution anaconda will also install Python on your machine so you don't have to download Python separately. Here we will click on the Download Now button and choose the Python 3.6 version to download. version 3.7 3.8 or something like that.
introduction to python with anaconda for beginners
Hello, please do not download Python 2 as it is an outdated version and some things may not work while downloading. Let's take a look at a very useful resource, the anaconda documentation, which can be found on dark stat. aniconic in slash anaconda or you can click on the anaconda documentation link at the bottom of the download page whenever you have a problem with anaconda, this documentation and your preferred search engine will be your best friends. You can see that there are many useful links and information. like chichi or some information about anaconda working with PIP which is a different package manager for

python

, on the left side you can find the installation link where you can find all the necessary help in case you face any problem with installing anaconda here you can We also find package lengths, we can find all the packages that come with anaconda, let's quickly see all the packages that come in anaconda and since I am running Mac OS, I will click on Mac OS here and on this page we can see the list of all the packages that are compatible or come pre-installed with anaconda, there are tons of them which is a great reason to use anaconda because if you didn't have anaconda you would have to install and manage these packages manually which can cause a lot of headaches. let's see if our installer has downloaded yet, so now we can run it.
This installer is pretty easy to follow, mostly it will just be clicking continue, so let's do it twice and on this page we should notice that the installer tells us about the fact that this installation will modify our path, what does that mean? ? Well, the path tells our operating system which directories to look in to find executable files. Modifying the path means that we add a piece of code that will point our computer to the directory with the executable files. This will allow us to execute various commands from the terminal window and is necessary for the correct functioning of anaconda.
Sometimes we need to modify the path manually, but this installer will do it for us, which is fantastic. We can continue with the installation now here. Will the software license agreement agree to this because if we don't we can't install it and on this screen we'll take a quick look at the customize option. Here we will see that the installer will install anaconda 3 and if we click on that confirms right here that the installer will modify our path, you could realize and then followed that you do not want to modify the path if you had a reason for it, but we will leave this option alone, we can go back to the standard installation. configure and continue with the installation, since I already have an account installed.
I'll let you pause the video, finish the installation, and come back when you're done. I hope the rest of the installation process goes smoothly now that we're done, let's quickly confirm that the installation added anaconda in our path. I'm not good enough with Windows to guide those on those operating systems through the following steps, so apologize for that, as long as you know how to change a directory, open a file, and list files on the command line that You should be able to still be on your Windows machine, open the terminal window and make sure you are in your home directory; if it's not, you can make sure it's writing CD and tile since It won't change the director for me.
Now we will need to find a file that stores the code that modifies our route. The code can be stored in three different files. The file names would be dot profile, bash underline profile, or dot underline profile. RC. The files are always stored in your home directory which is where we are currently located and you may have one of those files or you may have two or even all three, they all serve the same purpose so don't worry if you only have one. to find which of these files we have let's list all the files in our home directory to do that type LS this will list the files in our home directory as you can see here however there are no files called dot profile which I try profile or bash Or see, that's because the files we're looking for are hidden to list all the files, even the hidden ones in our home directory, type LS.
Hey, now we can search all the hidden files whose names usually start with dog. look and we can find that I have a bash underscore profile right here, you might have bash RC or you might just have that profile. Let's review the contents of this file to confirm that the installer added anaconda to our path and how it did so to open the file, tap Pico and the name of the file, which in my case is that bash underscore profile, but in your case could be bash RC or profile. If I click enter, I open the file within the file.
I can see all the content and I can see three lines of code, each of them adding a different directory to our path. This line, for example, tells the operating system to look for executable files in the three-slash Anaconda directory. The line above adds a directory for my development desktop application to work with. the first line adds two more directories, one is here and the other is here, they are separated by a column. If you install a program that did not automatically modify its path, this is the file you want to access and edit, we can exit. this file by pressing ctrl + when your computer searches for executable files.
Right here, the last path is the Anaconda path that was added by the Anaconda installer, so what this allows us to do is run various commands through the terminal window, such as installing new packages with Conda install. I would do Quinta install and then the package name or I can check the version of anaconda that is running with which I would do that and Conda - capital B, this will show me that the version of anaconda that I am running is one point six point nine and We should now have a good understanding of the path and how our computer knows where to look for executable files.
Now we have successfully installed anaconda and understand how PAP works. Now we can try to open anaconda. We have two options that we can expect among all our applications. be here anaconda navigator or we can type an account in a vagator and press return creator so this command works thanks to our route that we installed and modified with press return, we should see that Dan Khan is opening now, okay, so in the On the left side you can see there are a couple of tabs we won't use them too much but it's good to know what's inside in the environments tab you can create and manage environments, in the learning tab you can find some articles and resource videos learning in the Community tab, you can enjoy various communities where you can also learn.
There are a couple of apps on the main dashboard that Anaconda comes with, such as Jupiter Lab's Joker notebook and Spider. We will focus on Spider, which is integrated development. environment for

python

comes with anaconda, let's launch since spider is where you will spend most of your time while coding, let's get a little familiar with it. On the left, you have the text editor right here, here you will write a large text. code snippet that you want to save and run repeatedly on the top right, you can switch between the help file expert and the Variable Explorer window depending on what you need, for example I can type int in the help window which will show information about the in function at the bottom right you can find a console where you will spend a lot of time testing your code, so the editor is fine, you will write your programs and the console is where you will test these short code snippets before we start writing A program.
Let's try to run a run together for a moment so we can understand the syntax of Python. To do some simple calculations, all we need to do is write the operation we want to execute. Press Enter. Let's try to write 2 more. 3 that we just wrote is an expression that consists of a value and operators, the two values ​​we write are 2 and 3, the operator is the plus sign, expressions always evaluate to a single value, in this case the expression 2 plus 3 will evaluate to 5 You can see that Python took the expression 2 plus 2 as input and gave it a single value 5.
You can also do other types of expressions like multiplication, for example, 4 by 5 or division like 10 divided by 2. With this we introduce the first data. integer type other common data types are force floats and boolean strings are sequences of characters and we usually use this data type to start words and sentences, unlike numbers, strings must be enclosed in quotes, let's try to create a chain. Hello, don't forget. we put quotes and got the return of a string. Hi, We can also perform some operations on strings like adding two strings along with the plus sign. Let's try adding hell and Oh.
Furthermore, this is also an expression and consists of two hell values. and oh and the plus operator sign again this expression like any other expression is evaluated to a single value in this case hello another type of data is a float floats are numbers with decimal points just like with integers, you can perform operations math with them, let's try to multiply two point three by four point four and this expression evaluates to 10.12 another type of data is intimidation which can be true or false you can only have these two values ​​it is not common to use traditional plus and minus operators with booleans in instead we use and and u operators, the final operator says that the boolean value has to be true for the expression to evaluate to true, for example, the expression true and true will return true if we say true and false and false, the expression well, We will evaluate it to false.
Because one of these two values ​​is false and for this expression to be true when there is an end operator, both would have to be true, the or operator says that we only need one value to be true for the expression to be true.evaluate to true for example true and true or false have a value eighths of true false we will write it - true true or true will also evaluate to true the only way to make this type of expression evaluate to false is values ​​false or false and Expressions are essential to programming, but they wouldn't be very useful if we couldn't store them.
The good thing is that we have variables with variables, we can store values ​​for later use, we can also store expressions as they always violate up to a single value to store. a value in a variable we use a silent declaration the declaration consists of a variable name and an equal sign and the value let's try to store the string hello in a variable called foo let's write the name of the net variable foo the equal sign and the value hello here This part is the name of the variable, it is the equal sign and it is the value we are trying to store.
If you press Enter, we can see that in our Variable Explorer the value appeared. Now it shows us that we have a variable called foo which has value hello, the data type of the value is STR which means string, you can easily overwrite the value in the entire variable by assigning it a different value, let's try to do that technology foo with equal sign and one plus two. Now remember that this is an expression that will evaluate to a single value, one plus two will evaluate to three, so agree to return the variable that has foo. has been overwritten now the new value is three because one more to evaluate it to three the type is no longer a string but an integer now the three is stored in food we can use foo in an expression for example let's try adding food to four more four, the expression will evaluate to seven, this is because when Python evaluates expressions it replaces the variable with whatever it stores, since food stores three it replaces it with three, so in the end writing food plus four It's the same as writing three plus four there.
It is one more data type that we will use today the name of the data type is lists and lists is used to store multiple values ​​if we wanted to store the number one, two and three without lists we would need to store each of them. in a different variable but the list stores them all in a single variable like this one two three the list starts with an open bracket and ends with a closed bracket the values ​​we store in the list are separated by commas this is the first value in the list and is one this is the second value in the list and is two this is the third value in the list is three it is important to note that the first value in the list has an index of zero the second value in the list has an index of one and a third value in the list has an index of two, let's try to store this list inside a variable called bar the bar is equal to one two three now, when we press return, you will see that in a Variable Explorer we will have a new stored variable, the variable type is list, the name is bar, and the value is a list consisting of three different values.
Now, if we call the variable bar, what we get is a list of three values. If we want to return a specific value from the list, for example, the first value, we can do it by adding a square bracket after the variable call like this, that bar, let's try, let's try to return the first value in the list that is at the index of zero, then we'll type zero in square brackets and press Enter. We will get the specific variable we requested, if we want to return any other value, all we have to do is call the variable with the square. square brackets containing the index of the value, let's say we want to return the second value in the list, which is 2, all we have to do is call the opening bar of the square bracket, the index which is 1 and close the square bracket, now I'm going to press enter. we will get the value 2 Now that you know the basic syntax of Python we can create a simple program, as I mentioned above there are a lot of things that can be done in Python, unfortunately covering how to write complex programs with many packages is beyond the scope . scope of this short video, which means I'm just going to show you a short program.
What we will create is a restaurant selector. This restaurant pickle will store restaurant analysts and a random number generator. We will choose a restaurant from said list. able to remove restaurants from the list as well as minus the restaurant that we have stored in this program, we will also use conditional loops and functions. If you have never heard of any of these terms, try to follow them as they are quite easy to understand. A quick internet search can also help you if they don't make any sense. Remember that you don't need to understand every statement in the code, but rather try to understand the big picture.
Let's start opening a new file. we can press command N or go to file and press new file. What we will have to do is create a list, let's call it star restaurants list and this list will store some restaurants that we can do. Trébol de Polanco, don't forget to make a quote. marks around your strings and let's make sweet green greens and that should be enough for now these are the restaurants that the program will choose when choosing a random restaurant, which reminds me that we need to import a random module for this. The module will choose a random number and help us determine which one is trying to go here.
The program only tells us that chance has been important, but we have used it in our code, which is very unhelpful later when choosing a random restaurant. trying to call the random number generator will generate a number in the range that we specify in parentheses here if we do a 0 to 2 it will make numbers from 0 to 2 0 1 2 now if we have a list of restaurants here if we run this of course first we have than save it, let's just call it, take it, save it now if we run this file, nothing happens because we haven't printed it on the screen, so we will have to use the print now function, if you run it, let's go. to get a random number, the random restaurant, this time we have sweet green, if you run it again we will get something else or the same, let's try to run it again.
I have the following code. Now we get to Clover and then I got. Sweety Greens again, so this is working. What we need to do now is put it in a function, so we'll define a function called choose restaurant and we'll put this print statement inside the function, so this is a function definition statement. and inside the function there is a print function that will print the random restaurant. Now we also want to have a way to add any restaurant, so we'll define a function that will allow us to add a restaurant to our list, let's call it and it's general. this function will take a parameter, let's call it name and all we have to do is say restaurant list dot add this is a method of the list object, they will take value and we will pass it to the end of the list so that mr. list of neurons here, if you run this object around us and if we say it's tyrant and give it a name, let's drill down, you can see here in a very small Explorer that the dig will appear at the bottom of the list, here it is. so it's working, it's great, let's define a function that will remove a restaurant from this list, let's call it rent.
This function will also take the name of the restaurant that we want to delete and to delete something from the list I will call the name of the list that we uploaded oh geez I don't know the restaurant but first delete the restaurants please don't and that will take the parameter, so now if we call delete, I scramble it and say we want to delete below. see here that next Co will be removed from the list, there it is, it's gone now you can notice that dig is no longer here as well, that's because this list is started every time we run the program, so every time we we run it, The list will be created from scratch, so now when we run it again the focus comes back here.
Now we're going to create a really simple interface for the user to use so that they don't have to type delete restaurant in a restaurant and choose restaurant every time. If you want to use this program, we'll use a while loop for that, so while something Whether it's true, this is an infinite loop and you don't want to do it, you need to make sure there is a way for the user or the program. to end this loop and we'll do it with the break statement, but if you were to run something, loop in your program, but it won't work, so what we want to do is print a little message to the user and give them some options. we can choose so the first option would be to list all the restaurants and we haven't implemented the function yet but we will soon.
The second option would be to add a restaurant. The third option is to eliminate the restaurant. The fourth option will be to choose. restaurant and the fifth option would be to exit the program, so this add a restaurant option will use our add restaurant function. Delete restaurant will use the delete restaurant function and the large restaurant will use the largest restaurant function now. If you have the right to run this program, you will see that this message will be printed to the user over and over again until you stop it with Ctrl C. This is what happens when you have an infinite loop in your program.
Let's try to do it. I'll show you what it looks like. you will see how it prints in print and print it again and again. I will stop the execution of the code and try to do so, so I used control C to interrupt the execution of the program, otherwise you will have executed it forever. We will add some if statement, so if Oh, before that we will have to ask the user to select one of these options, we will do it with an input function, so in the input we will ask the user to select the option of select one option that is good enough, I think and save the selection and a variable, let's call the variable selection now, once they select, they will execute their selection through a series of if statements determine which of these functions we want to execute, so if the selection is equal to one, then here we will implement the restaurant list a little later.
If so, if this is not true, it will go to the other line to Co, which is here, and check whether this is true or not, so let's say the selection goes to two and If the selection is equal to two, we will want add a restaurant, then what we'll do is call the add restaurant function, that's the restaurant. Now you also need to ask the user to enter the name of the restaurant they want to add and we will do it again with the child function, so a name is equal to enter and we will ask the user to enter their restaurant.
Please, we have been very kind to them. Here I can only say type and here in the parameter we will place it. name more if so, if none of these are true, we'll move on to the next if statement here and it'll check if this one is true or not, three so you know like three, we'll want to remove the restaurant and again. We will have to ask them for the name of the restaurant. Do you want to delete? Please enter the name of the restaurant you wish to delete. To add, let's add a little more clarification so you know what kind of what. is happening now we will call the function to remove s, we will go around and enter the parameter and the name, then we will go to another if statement or select floor so that each of these determines whether the if statement will go to the next if statement or no, this expression will evaluate to true, the code inside the if statement will be executed, so if you, if the user puts one, then the selection here will basically be replaced by one and one is actually equal to one, so which would mean that this expression would be one or it would actually look like one is equal to one, which evaluates to true.
I'll show you here. This evaluates to true, meaning that this expression would evaluate to true and the code within this will be executed. I change it back to selection, the same would be true for this if if the user selected two, this would return false because two equals one will evaluate to false, it would move on to the next statement which is here and it will check if 2 equals 2 that will be would evaluate to true and the code within this statement would execute the next selection would be a typical restaurant, so we would execute the large restaurant function.
Now this function does not need any parameters and we certainly do not need to ask the user to enter any and the last option, the user simply has to log out, so say: "OK", LF selection. L F means else if so, if else, if this is true, when this, else, if true, Ventus, else if this is true, friend, is, etc. if this is equal to five interrupts, then this statement here will exit the infinite loop at this point, we can try to run the program that I think was expected in the children's blog, okay, so it actually wants us to have Lester write something here .
We don't have anything, we don't have any functions to put there yet, so let's create one that defines a list of functions and in this functionwe will go through each item in the restaurant list and print it for each turn and the list of most restaurants, so what? this says that it is for each item or for each value that will be under Co clover and sweet vegetables and restaurant list restaurant list pray, do something, then do something, everything that is here will be done for each value in the list, What we want? What we do for each value in the list is we print it, so what we're going to do is we're just going to say print mister run and now every time we call this function, the function is going to go to the list of restaurants, it's going to go through each of these items and will print. them we can add the function in our if statement, let's say list restaurants and since we don't need any parameters it will just list all the restaurants, we don't need to ask the user for the information, he must be nervous, I'm you, yeah. should be correct no, it is correct, let's save it and run the program.
If I click run file, I'm prompted to make a selection, so what it did was print this part of the code, now it's asking me to make a selection right here with this input function, so what I'm going to do is say that I want to list all the restaurants. I'll click on one now, it lists all the restaurants here. Bullock or clover and sweet greens. It looks a little sloppy because it's true, he printed it right after. my selection so we can make it look better by printing an empty line so there is little space between this line of code and just print an empty line now if you would like to add a restaurant, let's try to do it, let's show you press - now we are asked to add a restaurant.
Let's go deeper again. Let's press return. No, nothing happened, but at least I think it seems to be happening, but if I press, press 1 again, the rest of the restaurants will see that it's drill down. now here, so profit is part of the list, if I want to delete the restaurant, let's press 3, let's try to delete the clover, press return now again, nothing seems to happen, we could implement a small message to the user somewhere down here it would say you have successfully removed Clover from the list, but you don't have to spend time on that right now, but to check whether it has been removed or not, I can press what type it returns and I will see that Clover is no longer part of it. from the list now, if I were to accidentally type anything other than one of these five numbers, if I press L, for example, type O and press Enter, it will just go through the loop again because while this loop is true, it will always run, for What it would be nice to read a little message to the user about what happened, why they are being asked to do it and put something back in so that the final part of our code is something else and if none of this is true then the last statement here and we want to say something like please select one of the options above, so now when we run it and the user makes a wrong selection, it will tell him that it was a mistake, he didn't select any of the correct options and it will ask him select one of the previous options let's try to get out of this again for now there are more than five no program has finished running now we have to run it again so that all the changes we have made in a code are made let's try to press elegant we write the wrong option it tells us an error, select one of the options above, which is exactly what we wanted if we wanted to make a brick.
I want to have a line between these two messages, we can just put a line break, so now we would put a backslash n if If I printed it again, it was actually nonsense, there would be space between the two of you, so look a little better. Typographic error. Press Enter. There is a small space between the two. We could do that. I don't want each of these messages so that everything is It's better that we don't have two messages next to each other, but for now it looks pretty good. There is one more thing that needs to be done before the program is completely finished and that is to make this random integer generator flexible depending on how many elements we have. we have in our list of restaurants right now it will return numbers from 0 to 2 randomly and depending on what it returns it will select one of these elements in the list if it returns 0 it will return the first element if it returns 1 we will get the second element, if it returns 2, will get the third item, but if we were to add one more item to our list, which we can do with this add the rest function, this restaurant would never be chosen because this random integer generator will never be. returned the number three, which is the index of this value, so what we need to do is find the length of this list so that this random integer generator can return values ​​depending on how many elements we have inside, so what we need to do is do is call the length function and well, we'll put the list of restaurants there.
Yes, this length function will return a number depending on how many islands we have in this list, so in this case we will return 4 1 2 3 4, but what we really want is 3. because we want the index, not the actual length, so what we need to do is minus 1, so now I will return numbers from 0 3, let's try to run this, if it works, let's save it. We have an error here in the restaurant list. Now it should work, let's run the program, choose a restaurant, sweet, green, clover, sweet, green again, look, oh, so I was able to get the last item in the list, which is exactly what we want.
It now works properly and you can be very happy with it. the program, there are a few things that could be done to make it even better, but for now it's pretty good, now that you're done writing your program, let's try running it in the terminal so you don't have to open Spyder every time if I want to use this program to select the restaurant, let's open a new window in my terminal and here I will have to go to the location where the file is stored, in my case it is on the desktop, so I will type change directory and I will go to desktop desktop now that I am on the desktop I can list the files here.
I can see that I have two files that I didn't make and we will have to change the permissions of our restaurant selector on that py file to make that type. CH m OD + file you want to run. I think our case is the restaurant selector. If I press return, a message should appear with something we've already seen. If I press one, they list the restaurants I've stored, like everything we have. I've done it before, if I press choose, I'll choose one of those for the restaurant, it chose sweet, it means I do it again, it's under the echo.
If I click five, it will exit this program in the last part of this tutorial. I would like to show it. you a more complex file or program that can be created with Python. I'll open a program I wrote while preparing for the introductory data science class offered here at Suffolk. This program accesses the world data book found on the CIA Website, you would just open it very quickly, the program collects interesting information about each country in the world and saves it in the CSV file so that the type of information that is search for your area GDP roads railways the type of The program called web paper extracts data from a website.
I also show you the website from which it extracts the air. Let's go to Safari, open a new page, so here's a list of countries. Here they all are. There are more than 150 countries. and it goes through and for each country, it opens the web page, it finds the area, the total area, it also finds information about the GDP which is somewhere down here. I think the economy finds the total purchasing power and I also find the length of the railways and highways. So the duration of always is here, so you can imagine how long it would take you to get it by hand to go through each of those countries and get that information now.
If I run it, it will run for a while considering it goes through more than 150 web pages, so now you can see that the program has finished running. It actually took a lot longer than I expected. It took about a minute to get to 150 pages. We can open the file right here. It is the output file. Look, I ate that CSV that is shorter in the finder and I look at the data, so for each of the countries it found, name it, it's the code, the area, the length of the road, the length of the railways, GDP and put it in this CSV file, there are more, oh, no more than 150.
That's 269 different entries, so in this program I went through 269 web pages and collected this data, so it took a minute. It's pretty good considering you had to download each of those web pages, so that's the end of the tutorial. I really appreciate it. your time. I hope I was able to teach you a few things. If you are interested in learning more about Python, I would recommend checking out a book called Automate the Boring Stuff with Python, which is a great resource for

beginners

and will teach you everything. you need to know not only about Python but also about programming.
It's a good start. You don't even need to buy the book because the author distributes it for free and there is an HTML form on his website that appears on the screen. The website is automated. boring stuff com if you prefer to learn from a PDF or a hard copy, it's worth the $20 or how much it costs to buy it. I learned a lot from him. Another good resource is data camp. Don't worry if you are interested in using Python for data science. will teach you a lot less than the basics, but if you already know it's an amazing resource, the Suffolk University Information Systems Club or you can also give yourself access to all the paid content because the camp communicator was very kind to give them access free to all club members too, if you would like to give me feedback or have any questions about this tutorial I would be happy to chat with you, you can contact me at em Kowalski at SU, Suffolk, edu and for now happy coding, thanks again .

If you have any copyright issue, please Contact