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.

You can examine more options at the following URL: http://pandas.pydata.org/pandas-docs/stable/options.html.

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.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset