Try translating the Python Data Science Handbook into Japanese

Additions while making it public ...

Python Data Science Handbook
(Python Data Science Handbook)

1. IPython: Python better than Python
(IPython: Beyond Normal Python)

There are many options for the Python development environment, and I often wonder which one to use for my work. My answer to that sometimes surprises people. My favorite environment is to use Ipython and a text editor together. (In my case, I use Emacs and Atom properly according to my mood) Ipython (short for Interactive Python) was developed by Fernando Perez in 2001 as an extended python interpreter and has grown into a project focused on producing "tools for the entire life cycle of research computing." If python is the engine for our data science tasks Ipython can be thought of as an interactive control panel.

Ipython is a useful python interactive interface, but at the same time brings many useful (grammatical) (extended) features. (The following are especially useful.) In addition, Ipython is closely associated with the ** Jupyter Project **, which develops browser-based notebooks to help us develop, collaborate, share, and present data science results. The Ipython notebook is a special case of the many Jupyter notebooks, including notebooks for Julia, R and other programming languages. An example of the convenience of the notebook format is that you don't need to look at anything other than the page you're reading. This is because all of the manuscripts in this book consist of a set of Ipython notebooks.

IPython is an effective use of python for interactive scientific, data-intensive computing. The chapter begins by stepping into some of the features of Ipython that are useful in data science, especially the grammar that Ipython provides beyond the basic functionality of python. Next, we step into some of the more useful worlds of "magic commands" that can accelerate the daily tasks of creating and using data science programs. Finally, we'll touch on some of the notebook features that help us understand the data and share the results.

Shell or notebook?

There are two uses for Ipython discussed in this chapter. Ipython shell and Ipython notebook. Most of the content covered in this chapter is relevant to both, and the examples presented will switch depending on which is more convenient. There are a few parts that are only relevant to either, but then I will state that explicitly. Before we get started, let's talk about how to launch the Ipython shell and Ipython notebook.

Launch the Ipython shell

This chapter is not designed to be passively learned (as is the case with most of the books). While reading this chapter, we recommend that you try it yourself using grammar and tools. The muscle memory provided by this is far more useful than what you would simply get by reading this chapter. Start by typing ʻipython` on the command line and launching Ipython. If you have Anaconda or EPD installed, you should have a suitable launcher.

Type it in and you should see a prompt like this:


IPython 4.0.1 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.
In [1]:

Now you are ready to move on.

Launch Jupyter Notebook

Jupyter Notebook is a browser-based IPython GUI with a rich set of dynamic display features. In addition to being able to execute Python / IPython syntax, users can include formatted text, static or dynamic visual effects, formulas, JavaScript widgets, etc. in their notebooks. What's more, these documents can be stored in a format that others can do on their own.

You can view and edit IPython notebooks in a web browser window, but you need to connect your web browser to a python process to execute python code. This process (also known as the kernel) can be started by running the following code in the shell.


$ jupyter notebook

This command starts a local web server that you can see in your browser. A log of what this server is doing is immediately spit out. As below.


$ jupyter notebook
[NotebookApp] Serving notebooks from local directory: /Users/jakevdp/PythonDataScienceHandbook
[NotebookApp] 0 active kernels 
[NotebookApp] The IPython Notebook is running at: http://localhost:8888/
[NotebookApp] Use Control-C to stop this server and shut down all kernels (twice to skip confirmation).

After running this command, the default browser should automatically open and direct you to your local URL. (The actual address depends on the environment.) If the browser does not open automatically, you can open the window manually by jumping to the following address. (Http: // localhost: 8888 / in this example)

IPython help and documentation

If you don't intend to read the other sections in this chapter, just read this section. Because I found that the tools discussed here contributed most to improving IPython for my workflow. When a tech-minded person is asked for help by a friend, family member, or colleague about a computer problem, they almost always know how to get to the answer as quickly as they know the answer to the problem. This is very important. The same is true in the world of data science. Searchable web resources, such as online documents, mailing list threads, and StackOverflow answers, are rich in information. Even if it's (or especially) a topic you've searched for in the past. Becoming a true expert is not so much about learning the tools and commands that you can use in any situation, but how effectively a web search engine can find information you don't know.

One of the most useful features of IPython / Jupyter is to close the gap between users and document types and searches to get the job done efficiently. While web search still serves to provide answers to complex problems, a surprising amount of information can be obtained only through IPython. Below is an example of a question that Ipython can answer with a few keystrokes. ・ How should I call this function? What are the arguments and options? -What is the source code of this python object? -What's in this imported package? What attributes and methods do you have? From now on, we'll discuss Ipython tools that give you quick access to this information. That is, "?" To find the document, "??" to find the source code, and the tab key for auto-completion.

Accessing documents using?

The language python and its data science ecosystem are designed with users in mind, and one of the major thoughts is access to documents. All python objects contain references to strings called docstrings. These are most often a brief summary of the usage of the object. Python has a built-in function that accesses and displays the information help (). For example, if you want to see the documentation for the built-in function len, you can do the following:

In [1]: help(len)
Help on built-in function len in module builtins:

len(...)
    len(object) -> integer

    Return the number of items of a sequence or mapping.

Depending on the interpreter, this information may be displayed as inline text or as a separate pop-up window.

Because it's common and convenient to find help with an object, Ipython provides access to this document and related information with a short "?".

In [2]: len?
Type:        builtin_function_or_method
String form: <built-in function len>
Namespace:   Python builtin
Docstring:
len(object) -> integer

Return the number of items of a sequence or mapping.

This notation is valid for anything, including methods of objects.

In [3]: L = [1, 2, 3]
In [4]: L.insert?
Type:        builtin_function_or_method
String form: <built-in method insert of list object at 0x1024b8ea8>
Docstring:   L.insert(index, object) -- insert object before index

Or even the object itself has a document that starts with type information.

In [5]: L?
Type:        list
String form: [1, 2, 3]
Length:      3
Docstring:
list() -> new empty list
list(iterable) -> new list initialized from iterable's items

The important thing is that this also works for functions and your own objects! Suppose you define a docstring for a small function like this:

In [6]: def square(a):
  ....:     """Return the square of a."""
  ....:     return a ** 2
  ....:

When creating a docstring for this function, please note that this time we just wrote a single string literal. This is because python's "" "is customarily used across multiple lines, and docstrings are usually multi-line.

Now, let's use "?" To find this docstring.

In [7]: square?
Type:        function
String form: <function square at 0x103713cb0>
Definition:  square(a)
Docstring:   Return the square of a.

Recommended Posts

Try translating the Python Data Science Handbook into Japanese
Try translating with Python while maintaining the PDF layout
Data Science Cheat Sheet (Python)
Try "100 knocks on data science" ①
Try scraping the data of COVID-19 in Tokyo with Python
[Data science memorandum] Confirmation of the contents of DataFrame type [python]
Start data science on the cloud
Try the Python LINE Pay SDK
Try using the Python Cmd module
Try to image the elevation data of the Geographical Survey Institute with Python
Try using the Wunderlist API in Python
Generate Japanese test data with Python faker
"Data Science 100 Knock (Structured Data Processing)" Python-007 Explanation
"Data Science 100 Knock (Structured Data Processing)" Python-001 Explanation
Download Japanese stock price data with python
I took Udemy's "Practical Python Data Science"
[Python] Try pydash of the Python version of lodash
"Data Science 100 Knock (Structured Data Processing)" Python-002 Explanation
[Python] Data Science 100 Knock (Structured Data Processing) 021 Explanation
"Data Science 100 Knock (Structured Data Processing)" Python-005 Explanation
"Data Science 100 Knock (Structured Data Processing)" Python-004 Explanation
Try hitting the YouTube API in Python
[Python] Data Science 100 Knock (Structured Data Processing) 020 Explanation
[Python] Data Science 100 Knock (Structured Data Processing) 025 Explanation
"Data Science 100 Knock (Structured Data Processing)" Python-003 Explanation
[Python] Data Science 100 Knock (Structured Data Processing) 019 Explanation
Japanese translation: PEP 20 --The Zen of Python
Try python
Location information data display in Python --Try plotting with the map display library (folium)-
Try the python version of emacs-org parser orgparse
[Python] 100 knocks on data science (structured data processing) 018 Explanation
[Python] 100 knocks on data science (structured data processing) 023 Explanation
Try to decompose the daimyo procession into Tucker
Try it with Word Cloud Japanese Python JupyterLab.
Just add the python array to the json data
[Cloudian # 7] Try deleting the bucket in Python (boto3)
[Python] 100 knocks on data science (structured data processing) 030 Explanation
[Python] 100 knocks on data science (structured data processing) 022 Explanation
Try to solve the man-machine chart with Python
Try using the BitFlyer Ligntning API in Python
Python: Try using the UI on Pythonista 3 on iPad
Try using the Python web framework Tornado Part 1
[Python] Memo to translate Matplotlib into Japanese [Windows]
Try the free version of Progate [Python I]
[Python] 100 knocks on data science (structured data processing) 017 Explanation
Try CIing the pushed python code on GitHub.
[Python] 100 knocks on data science (structured data processing) 026 Explanation
[Python] 100 knocks on data science (structured data processing) 016 Explanation
Try using the Python web framework Tornado Part 2
Try implementing the Monte Carlo method in Python
[Python] 100 knocks on data science (structured data processing) 027 Explanation
[Python] Get the day of the week (English & Japanese)
[Data science memorandum] Handling of missing values ​​[python]
Try accessing the YQL API directly from Python 3
Try importing MLB data on Mac and Python
[Python] 100 knocks on data science (structured data processing) 029 Explanation
[Python] 100 knocks on data science (structured data processing) 015 Explanation
Try using the DropBox Core API in Python
[Python] 100 knocks on data science (structured data processing) 028 Explanation