在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:learn-co-students/jupyter-notebook-introduction-data-science-intro-000开源软件地址:https://github.com/learn-co-students/jupyter-notebook-introduction-data-science-intro-000开源编程语言:Jupyter Notebook 100.0%开源软件介绍:Jupyter Notebook CodeAlongIntroductionSo far, many of the readings and all of the labs you have been working with have been interactive. You are working in an environment that allows us to both display text and run Python code. In this lesson, we explore Jupyter, the software powering these interactive documents. Jupyter BackgroundJupyter is a web application that allows someone to create and work with documents that have live code. It's a very popular tool among data scientists, as it allows for both explanation of thinking behind code as well as the code itself. Introduction to cellsThe notebook itself consists of cells. Double click on this content to see what I mean. Once we double click on a cell, we are in insert mode. This means that we are able to edit the cells, just as you would if this were a word document. We can tell that we are in insert mode because of the green border around the cell. After entering insert mode for this cell, change some content. Don't worry about what you change as we can always undo it. We can revert our changes to a cell by making sure that we are still in insert mode and by pressing To get out of insert mode and see the effect of our changes, press Adding and Deleting CellsWe have already seen, to alter the contents of a cell we simply double click on that cell, bringing us into insert mode, and then change the contents. Now let's see how to add, and delete cells from escape mode. Adding cellsIf we wish to quickly add a new cell we can do so with the following steps:
Deleting cellsTo delete a cell we once again should be in escape mode, and then press the Of course, we'll want a way to undo our deletion. From escape mode, you can press Go to escape mode and press Then bring it back with Types of CellsThe current cell and every other cell in this lesson has been a markdown cell, meaning that it allows us to write text and stylize that text. For example, if you surround some text with stars on either side the text becomes bold. That's markdown. Cells can also have a type of code. If we are writing in a cell that is for Python code, everything in that cell must be valid Python or we will see an error. This is a python cell without valid Python so we will see an error So, a cell must either be of type markdown or of type code, in which case all of the contents must be valid Python. It cannot be both. We can quickly change a cell from markdown to code with some keyboard shortcuts. From escape mode, we change a cell to type code by pressing the letter Anytime we create a new cell, say with the shortcut key View All ShortcutsPress the key Working with Python in JupyterOk, now that we know a little bit about adding and deleting cells, as well as changing cell types from markdown to code, let's focus on working with Python in Jupyter. We'll go into a large amount of detail about working with a Jupyter notebook in Python, but the main takeaway is this: if we see a Python cell, we should press The major gotcha in working with Python code is that we must execute the cells in order for Python to register the code in them. So for example, just seeing the cell where we define name = 'bob' If we try to reference that variable later on without having executed the cell, Python will tell us that it is not defined. name
To execute or run a cell, we must press age = 14
age
As you can see the variable One tricky thing to note is that assignment, the action of assigning a variable, does not have a return a value. So, even though the cell is run, if the last line of cell is the assigning of a variable, nothing is displayed underneath. hometown = 'NYC' Notice, even after pressing shift + enter on the code above, nothing is displayed below. But if we reference the variable hometown
None Working through labs and readmesAs you read through labs we encourage you to press shift + enter on each of the Python cells. Often in labs, we will assign variables to data early on. Then we will ask you to work with data stored in those variables. To avoid going to the top of the lab to press The same thing goes for working through a Readme. The Readmes will often assign data to variables, and it may be nice to work with data stored in those variables later on. So it's a good idea to press SummaryIn this lesson, we learned about Jupyter notebooks. We saw that in Jupyter notebooks, we can either be in insert mode or escape mode. While in insert mode, we can edit the cells and undo changes within that cell with Then we saw how to work with Python code in Jupyter notebooks. We saw that to have our code in a cell executed, we need to press |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论