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

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.

主站蜘蛛池模板: 兴和县| 游戏| 海伦市| 林州市| 镇雄县| 台东县| 洱源县| 安阳市| 新竹县| 炎陵县| 新巴尔虎左旗| 望奎县| 钟山县| 永年县| 婺源县| 边坝县| 进贤县| 滨州市| 禹州市| 涟源市| 宁化县| 叙永县| 同心县| 濮阳市| 宜春市| 吕梁市| 鸡泽县| 瓮安县| 镇赉县| 九寨沟县| 弋阳县| 浪卡子县| 荣成市| 邹平县| 义马市| 隆回县| 蓝山县| 玉田县| 普兰店市| 融水| 湄潭县|