LoginSignup
2
2

More than 5 years have passed since last update.

Pythonによるデータ解析

Last updated at Posted at 2017-05-10

Pythonによるデータ解析

環境構築(Python 2)

仮想環境を作る

yml形式で以下のようなファイルを作成しておく。

name: 仮想環境名 (ここではpy2)
dependencies: 必要なパッケージリスト

name: py2
channels:
    - conda-forge
dependencies:
    - python=2.7
    - xarray
    - netCDF4
    - seaborn
    - numpy
    - matplotlib
    - scipy
    - pip:
        - cyordereddict
        - sqlalchemy
        - model-organization

その後、以下のコマンドで仮想環境を新規構築、アクティベートする。

$ conda env create -f environment.yml
$ source /home/user-name/.pyenv/versions/anaconda3-4.1.0/envs/py2/bin/activate py2
(activateをフルパスで指定しないと落ちる場合がある。)

AnacondaでPython環境を構築しているが、ほしいパッケージがcondaにない場合

$ source activate <anaconda環境名>
$ pip install <モジュール名>

既存の環境名の確認
デフォルトはroot

$ conda info --envs

jupyter notebook

localhostのポート番号を指定して立ち上げる。

$ jupyter notebook --port xxxx

あるいは、jupyter notebookの設定を編集する。
c.NotebookApp.portをコメントアウトしてポート番号を設定する。

$ .jupyter/jupyter_notebook_config.py
c.NotebookApp.port = xxxx

プロファイルの設定

プロファイルを作成していなければ以下のコマンドで作成する

$ ipython profile create

これにより、
~/.ipython/profile_default/ipython_config.py
が作成される。

以下のように編集すると、起動時に%matplotlib inlineが読み込まれ、matplotlibのグラフがインラインで表示されるようになる。

# lines of code to run at IPython startup.
# c.InteractiveShellApp.exec_lines = traitlets.Undefined
c.InteractiveShellApp.exec_lines = ['%matplotlib inline']
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2