iPython

<Python, iPython>エラー。。。 QxcbConnectionうんぬんかんぬん。。。

新しいものにひかれ、condaさんで、python3.6の環境を作成。 ちょれ~と、ipythonを起動したら、エラーになった。 QXcbConnection: Could not connect to display ちとぐぐった結果、~/.ipython/profile_default/startup/00-first.py中で、import matplotlib…

<Python, iPython, Jupyter> Historyをファイルに保存する。

iPythonで、ちょろちょろ実行した結果のhistoryをファイルに保存saveする。 In [170]: %history -f aaa.py File 'aaa.py' exists. Overwrite? y Overwriting file. 29個目の回答がそれだった。 さんきゅー。 stackoverflow.com

<iPython, html> HTMLの表示

ipython notebookでHTMLを表示する方法。 s = '<p>Hage</b>' from IPython.display import HTML html = HTML(s) html

<iPython, python> ipywidgets を試してみた。

iPython上でインタラクティブinteractiveな動作ができるipywidgetsを試してみた。 これで、スライダーsliderとかできる。 まずは、インストール。 conda install ipywidgets で、jupyter notebook立ち上げて、 次のコード書き込み。 %matplotlib inline impo…

<Jupyter, iPython> 00-first.ipy

Jupyterになった後、iPythonで設定していた、設定ファイルはどうなるか? いろいろやった結果わかったこと。 1 Jupyterで起動後も、iPythonの設定は、かわらず、~/.ipython の下にあるものを参照しに行く。 2 ただ、00-first.pyは、拡張子をipyにしないとい…

<Python, iPython, Jupyter> qtconsole

なんだかよくわからないが、ipython qtconsoleが立ち上がらない。 ImportError: No module named 'qtconsole' とエラーを吐く。 pandas-highchartsをアンインストールしてから、アップデートしたからか、、な? pip install qtconsole としたら、 ipython qt…

<Python, iPython> ipython notebookで起動ブラウザを指定

ipython notebookで起動ブラウザを指定する方法。 ipython_config.pyに下記を書き込む。(firefoxの場合) c.NotebookApp.browser = u'/usr/bin/firefox %s' ipyhton_config.pyはprofileがdefaultならば下記にあるはず。 /home/hage/.ipython/profile_default…

<Python, iPython> 出力の取り込み。

iPythonのコンソールにぺっって出力される結果のキャプチャーcapture方法。 その1 シェルコマンドshell commandをキャプチャー。 !付きで呼び出したコマンドの結果をオブジェクトに取り込む。 In [110]: ls In [111]: ls a b c In [112]: ls -l total 0 -rw…

<Python, iPython> どこでもPython

どこでもpython。ここは、pandasを読み込めた。へー。 www.pythonanywhere.com

<Python, iPython> %recall, 履歴の再実行

長々と探し続けてようやく見つけた。 iPythonでhistory -gで履歴番号を出し、履歴番号でコマンドを再実行する技。 %recallだってさ。 28: who 29: pwd 30: h -g In [40]: recall 28 In [41]: who 時間かかった。。。 マニュアル。 Built-in magic commands —…

<Python, iPython> %dhist

%dhist 行ったディレクトリの履歴が見れる。 で、cd -[n]でそこへジャンプできる。 ちと便利。 In [20]: %dhist Directory history (kept in _dh) 0: /home/hage 1: /home/hage/tmp 2: /home/hage In [21]: cd -1 /home/hage/tmp In [22]: cd -0 /home/hage …

<Python, iPython> %alias_magic をstartupに設定

マジックコマンドのエイリアス%alias_magicをスタートアップstartupに設定する。 ~/.ipython/profile_default/startup/00-first.pyに次の呪文を書き込む。 from IPython import get_ipython mgc = get_ipython().magic mgc('%alias_magic h history') stacko…

<Python, iPython> shellのaliasの設定

ipython上でのシェルコマンドshell commandのエイリアスaliasの設定方法。 まずは、次のコマンド実施。 そうするとホーム/home/hage/.ipython/profile_default/以下に下記ファイルができる。 [1:hage@hoge~]> ipython profile create [ProfileCreate] Genera…

<Python, ipython, pdb> デバッガー

Pythonのデバッガーpdb。 マニュアル(日本語と、英語) 27.3. pdb — Python デバッガ — Python 3.6.3 ドキュメント 27.3. pdb — The Python Debugger — Python 3.4.7 documentation ipythonからだと、-dオプションでスクリプトを実行すればオッケー! こん…

<Python, iPython> %history -g とキーボードショートカット

%history -g で履歴に履歴番号がついてでてくる。 %history -g df でdfをgrepした結果がでてくる。 へー。 あとはキーボードショートカット。まあ、emacs/bashとほぼ同じだね。 Ctrl-p または↑ コマンド履歴から入力した文字列で始まるものを遡って検索 Ctrl…

<Python, ipython> quick ref

いいもの見つけた。 Ipython-quick-ref-sheetsdamontallen.github.io

<Python, pandas> コマンドラインの出力を取り込み、データフレーム(DataFrame)へ

コマンドライン command lineの出力をpipeして、データフレームDataFrameへ取り込む方法。 いろいろ調べた結果下記で実行可能っぽい。 In [1]: %more aaa.csv a,b,c, 1,2,3, 4,5,6, In [2]: import subprocess In [3]: import pandas as pd In [4]: import i…

Python, plotly, ちょっとはまった件。legendがあると、、

legendを指定していると、matplotlibからplotlyへの変換に失敗するねー。 次のコードはだめ import matplotlib.pyplot as plt import numpy as np import pandas as pd import plotly.plotly as py df= pd.DataFrame(np.random.randn(100,2), columns=['a','…

Python, iPython, plotly, 散布図の作成 3種類とplotlyへ渡す

散布図の作成方法。 3種類発見したので、メモメモ。 あと、plotlyをipython中に表示させる。 import matplotlib.pyplot as plt import numpy as np import pandas as pd from ggplot import * import plotly.plotly as py df= pd.DataFrame(np.random.randn…

Python, iPython, plotly, plotlyとBokeh

PlotlyとBokehをWinpythonにインストールしてみた。 pip install bokeh pip install plotly Installation — Bokeh 0.8.1 documentation Python Graphing Library | Documentation and Examples | plotly 両方ともpythonで作ったplotをhtmlへ変換して、いい感…

Python, iPython, システムのコマンドを取得する

ipython にそのシステムのPATH上にあるコマンド群を認識させるには、、 %rehashx これで、環境変数$PATH (Windows だと %PATH% )以下のコマンド群がつかえるようになる。

Python, iPython, 初期化スクリプト

初期化スクリプトを置いて見た。 ただ、通常のスクリプトデバック時に必要なモジュールのimport忘れそうだけど、、 場所 ~/.ipython/profile_default/startup/ Windowsでは %HOME%\.ipython\profile_default\startup いれたモジュール import sys,os,os.path…

Python, iPython, オブジェクトの消し方

いろいろ動かしていて、ぐっっちゃになったので、全部消したい時。 でもディレクトリも移動しているので、オブジェクトだけ消したい時は、 In [59]: who a b c d In [60]: del a In [61]: who b c d In [63]: reset Once deleted, variables cannot be recov…

Python, iPython, ちょと使い方。

python script+引数/argvをipythonで実行するには、、、 %run hogehoge.py hagehage hohoho として、%run で走らせる。 これが runでも走ったけどね、、 またunix commandたちは、ある程度そのまま動く。 動かないものは、!を頭につけるらしい。 例えば !pi…