官术网_书友最值得收藏!

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.

主站蜘蛛池模板: 嘉祥县| 都匀市| 石门县| 拜泉县| 天台县| 正镶白旗| 舞钢市| 扎鲁特旗| 紫云| 海晏县| 勐海县| 南靖县| 华池县| 石棉县| 台州市| 偏关县| 尼勒克县| 安顺市| 绍兴市| 海南省| 庆元县| 通城县| 乌海市| 兰西县| 莒南县| 瑞丽市| 罗山县| 富源县| 岱山县| 虎林市| 泉州市| 新蔡县| 珠海市| 玛纳斯县| 南投县| 泽州县| 亳州市| 全椒县| 涪陵区| 兴义市| 鹤壁市|