- Learning pandas(Second Edition)
- Michael Heydt
- 348字
- 2021-07-02 20:37:06
Importing pandas
Every notebook we will use starts by importing pandas and several other useful Python libraries first. It will also set up several options to control how pandas renders output in a Jupyter Notebook. This code consists of the following:

The first statement imports NumPy and refers to items in the library as np.. We won't go into much detail on NumPy in this book, but it is occasionally needed.
The second import makes pandas available to the notebook. We will refer to items in the library with the pd. prefix. The from pandas import Series, DataFrame statement explicitly imports the Series and DataFrame objects into the global namespace. This allows us to refer to Series and DataFrame without the pd. prefix. This is convenient as we will use them so frequently that this saves quite a bit of typing.
The import datetime statement brings in the datetime library, which is commonly used in pandas for time series data. It will be included in the imports for every notebook.
The pd.set_option() function calls set up options that inform the notebook how to display output from pandas. The first tells states to render Series and DataFrame output as text and not HTML. The next two lines specify the maximum number of columns and rows to be output. The final option sets the maximum number of characters of output in each rows.
A sharp eye might notice that this cell has no Out [x]:. Not all cells (or IPython statements) will generate output.
If you desire to use IPython instead of Jupyter Notebook to follow along, you can also execute this code in an IPython shell. For example, you can simply cut and paste the code from the notebook cell. Doing so might look like the following:

The IPython shell is smart enough to know you are inserting multiple lines and will indent appropriately. And notice that there is also no Out [x]: in the IPython shell. pd.set_option does not return any content and hence there is no annotation.
- Mastering Visual Studio 2017
- Learning ROS for Robotics Programming(Second Edition)
- Mastering Adobe Captivate 2017(Fourth Edition)
- Getting started with Google Guava
- SoapUI Cookbook
- Visual FoxPro程序設(shè)計教程
- Mastering Julia
- Mastering LibGDX Game Development
- Apache Mesos Essentials
- Kali Linux Wireless Penetration Testing Beginner's Guide(Third Edition)
- Getting Started with Gulp
- BeagleBone Black Cookbook
- Python深度學(xué)習(xí):模型、方法與實現(xiàn)
- PHP編程基礎(chǔ)與實例教程
- 一本書講透Java線程:原理與實踐