3/21/2021

Set up Jupyter in PyCharm

In 2020, PyCharm started supporting Jupitor notebook in PyCharm. After trying, it is pretty handy as it has auto-completion feature and my own plugins in PyCharm. Most importantly,  I can still use IdeaVim and my hotkeys in PyCharm.  

In this post, I am going to show I do it and demo a small stock analysis project.

Here is how I set up:

Step1: Open PyCharm and select "New Project" -> Pure Python -> Select project location and enviroment.

In my case, I chose Pipenv as I got used to it.


Step2: Install dependencies

Go to the project root and create a requirements.txt, then paste the following dependencies to requirements.txt

notebook
jupyterlab
numpy
pandas
pandas-datareader
matplotlib
pipenv install -r requirements.txt
Now, it should start installing the above dependencies.


Step3: Create ipynb file and start coding

Create an ipynb file, called StockAnalysis. ipynb, then paste the below snippet of code to it.

#%%

from datetime import datetime, timedelta

import pandas_datareader.data as web
import matplotlib.pyplot as plt

%matplotlib inline


PAST_DAYS = 365
symbol = 'AAPL'
stock_data_src = 'yahoo'

end = datetime.today()
start = end - timedelta(days=PAST_DAYS)
stock = web.DataReader(symbol, stock_data_src, start, end)
stock['MA20'] = stock['Close'].rolling(20).mean()

#%%

stock['Open'].plot()
stock['MA20'].plot(label='MV 20')
plt.legend()

Step4: Run it

With Jupyter feature, you can execute cell code(Check the screenshot). Now, you should be able to enjoy coding and doing analysis powered by Jupyter.



No comments:

Post a Comment