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
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
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()