2
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

jupyter環境に自動でライブラリをインポートする

Posted at

初めに

Jupyterでよく使うライブラリを毎回インポートしたり同じ設定を書くといった何気ないめんどくさい作業を自動化できないかと思い調べたので共有します。

方法

~/.ipython/profile_default/startup/start.pyに記述した内容がIpythonが立ち上がるタイミングで毎回実行されるため、この機能を利用します。
例えば、以下のような内容を記述しておくと、ライブラリのインポートの他にも設定などを統一できます。

import pandas as pd
import numpy as np

# Pandas options
pd.options.display.max_columns = 30
pd.options.display.max_rows = 20

from IPython import get_ipython
ipython = get_ipython()

# If in ipython, load autoreload extension
if 'ipython' in globals():
    print('\nWelcome to IPython!')
    ipython.magic('load_ext autoreload')
    ipython.magic('autoreload 2')

# Display all cell outputs in notebook
from IPython.core.interactiveshell import InteractiveShell
InteractiveShell.ast_node_interactivity = 'all'

# Visualization
import plotly.plotly as py
import plotly.graph_objs as go
from plotly.offline import iplot, init_notebook_mode
init_notebook_mode(connected=True)

終わりに

こういう細かいチップスで生産性高めていきましょう👍

2
5
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
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?