IPython is a very powerful interactive environment that is essential for exploratory data analysis. You will be able to execute code from an interactive operating environment, and you will be able to fully experience the productivity of the interpreted language. I think you can mention pry in Ruby as a similar environment, but IPython may be one step ahead in the perfection of the interactive shell. I think not.
The IPython community is developing fast, from version 1.0 released last summer 2013 to IPython 2.0 released this April 2014. Up to /version2.0.html), 650 pull requests have been merged with 400 issues and 4000 commits. Also, the 3.0 series is currently under development, and its roadmap can be found on GitHub. It has evolved in various points such as support for Python 3.x series based on a single code, and security has also been improved, so if you are using the old 1.x series, immediately update to the latest 2.0 series. Should be done. The latest version at the time of writing was released on 8/6 and has just been security fix version 2.2. /ipython/ipython/issues?q=milestone%3A2.2).
You can check the latest information from here. In addition, upgrade to the latest version as follows.
ipython --version #Check the version of IPython
pip install --upgrade ipython #Upgrade to the latest if old
You can also upgrade pip-installed packages to the latest, except for frozen ones:
pip freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs pip install -U
I think that Python always has a standard library to import. For example, sys, os and numpy as np.
It will be executed if you put the script you want to execute when IPython starts in the ~ / .ipython / profile_default / startup / directory. Note that the reading order is the dictionary order of the file names, so it will be easier to manage if you add a number to the beginning such as 00-first.py like the GNU / Linux daemon startup script.
import sys, os
import readline
import numpy as np
import scipy as sp
import pandas as pd
import matplotlib.pyplot as plt
It would be convenient to write at least this much.
A single? Before or after an object displays the docstring, and a?? Displays the source code. The source code is very powerful because it is syntax highlighted and displayed depending on the environment. Being able to easily see the code for each function in the library you want to use helps you understand the behavior.
ipython
df = pd.read_csv("data.csv")
df?? #The source code of the data frame is displayed
df.plot?? #The source code of the plot function is displayed(You can check options etc.)
It's too nonsense to copy the source code into an interactive shell because you want to test a piece of code in the middle of writing.
IPython can run existing source code with the% run command. Commands that start with this% are called magic commands. You can see what magic commands exist by pressing the tab key after the%. You can usually guess the meaning by just looking at the name.
%run ~/source/your_code.py
In the above example, not only will your_code.py be executed, but objects such as classes, variables, etc. will still be available in IPython.
There are times when you want to paste the code into an interactive shell, albeit a bit clunky. My recommendation is to use% cpaste.
%cpaste
#Then paste the code
Last time was also introduced at the end, but you can save the history to a file with readline.write_history_file.
readline.write_history_file("history.py")
It is also convenient to log with% logstart to save the entire session. By default, the history is saved in a file called ipython_log.py.
IPython has a lot of useful features that I can't even introduce. Read the original documentation is a good choice.
Recommended Posts