Skip to main content

Using Cursor with Jupyter Notebooks for Data Science

Cursor Jupyter Notebooks

Cursor 1.0+ added native support for Jupyter Notebooks, making it an excellent environment for data science workflows. This guide covers how to set up and use Cursor with .ipynb files, from basic editing to AI-assisted data analysis.

Prerequisites​

  • Cursor version 1.0 or newer
  • Python 3.8+ installed
  • Jupyter package installed (pip install jupyter)
  • .ipynb file or project with notebooks

Opening Jupyter Notebooks in Cursor​

Method 1: Direct Open​

  1. Open Cursor
  2. Go to File > Open Folder and select your project
  3. Click on any .ipynb file in the Explorer
  4. Cursor will open the notebook in the built-in editor

Method 2: From Terminal​

# Navigate to your project
cd ~/data-science-project

# Open in Cursor
cursor .

Method 3: Create New Notebook​

  1. Right-click in the Explorer sidebar
  2. Select New File
  3. Name it analysis.ipynb
  4. Cursor will create a blank notebook

Notebook Interface in Cursor​

Cell Types​

Cursor supports three cell types:

Cell TypePurposeShortcut
CodeExecute Python codeY
MarkdownWrite documentationM
RawUnformatted textR

Basic Operations​

ActionShortcut
Run cellShift + Enter
Run cell and insert belowAlt + Enter
Add cell aboveA
Add cell belowB
Delete cellD, D
Toggle line numbersL

Cell Toolbar​

Each cell has a toolbar with:

  • Run button (▶️) - Execute the cell
  • Cell type selector - Switch between Code/Markdown/Raw
  • Move up/down - Reorder cells
  • Delete - Remove the cell

Connecting to a Kernel​

Select Kernel​

  1. Open a .ipynb file
  2. Click Select Kernel in the top right
  3. Choose from available options:
    • Python environments (conda, venv, pyenv)
    • Remote kernels (JupyterHub, remote server)
    • Existing Jupyter sessions

Create Virtual Environment​

# Create a virtual environment
python -m venv venv

# Activate it
source venv/bin/activate # macOS/Linux
venv\Scripts\activate # Windows

# Install packages
pip install jupyter numpy pandas matplotlib seaborn scikit-learn

Register Environment as Kernel​

# Install ipykernel
pip install ipykernel

# Register the environment
python -m ipykernel install --user --name=myproject --display-name="Python (MyProject)"

AI-Assisted Data Analysis​

Analyzing DataFrames​

  1. Load your data in a code cell:
import pandas as pd

df = pd.read_csv('data.csv')
df.head()
  1. Run the cell to see the output
  2. Select the output table
  3. Right-click and choose Add to Chat (or use @notebook)
  4. Ask Cursor:
Analyze this dataset. What are the key patterns and insights?

Generating Visualizations​

Create a visualization showing the relationship between column A and column B.
Use seaborn with a regression line and confidence interval.

Cursor will generate the code:

import seaborn as sns
import matplotlib.pyplot as plt

plt.figure(figsize=(10, 6))
sns.regplot(data=df, x='column_A', y='column_B', ci=95)
plt.title('Relationship Between A and B')
plt.show()

Exploratory Data Analysis (EDA)​

Perform a complete EDA on this dataset including:
1. Data quality check (missing values, duplicates)
2. Descriptive statistics
3. Distribution plots for numeric columns
4. Correlation heatmap
5. Outlier detection

Using Cell Output as Context​

Inline AI in Notebooks​

  1. Run a cell that produces output (table, chart, etc.)
  2. Click the AI button in the cell toolbar
  3. Ask questions about the output:
What do these correlation values suggest about feature importance?

Notebook-Level Context​

Use @notebook in chat to reference the entire notebook:

@notebook Review all the analysis so far and suggest the next steps for building a predictive model.

Advanced Features​

Variable Inspector​

  1. Run some cells to create variables
  2. Open the Variable Inspector:
    • View > Appearance > Show Variable Inspector
  3. See all active variables, their types, and values

Debugging Notebooks​

  1. Set breakpoints in code cells
  2. Click Debug Cell in the cell toolbar
  3. Step through execution with F10/F11
  4. Inspect variables in the Debug sidebar

Exporting​

FormatCommand
HTMLFile > Export Notebook As > HTML
PythonFile > Export Notebook As > Python Script
PDFFile > Export Notebook As > PDF
MarkdownFile > Export Notebook As > Markdown

Best Practices​

Organize Your Analysis​

# Data Analysis Notebook

## 1. Setup
Import libraries and load data

## 2. Data Quality Check
Check for missing values, duplicates, and data types

## 3. Exploratory Analysis
Visualize distributions and relationships

## 4. Feature Engineering
Create new features and transform existing ones

## 5. Modeling
Build and evaluate predictive models

## 6. Conclusions
Summarize findings and recommendations

Use Markdown Cells for Documentation​

  • Explain the purpose of each section
  • Document assumptions and decisions
  • Add context for future readers

Clean Output Before Sharing​

  1. Clear all outputs:
    • Notebook menu > Clear All Outputs
  2. Restart kernel:
    • Notebook menu > Restart Kernel
  3. Run all cells:
    • Notebook menu > Run All

Troubleshooting​

IssueSolution
Kernel won't startCheck Python path and virtual environment
Imports failingInstall packages in the correct environment
Output not displayingRestart kernel and re-run cell
Notebook won't saveCheck file permissions
AI not seeing cell outputUse @notebook or select output manually

Example Workflow​

# Cell 1: Setup
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns

# Cell 2: Load Data
df = pd.read_csv('sales_data.csv')
print(f"Shape: {df.shape}")
df.head()

# Cell 3: Quick Profile
df.describe()

# Cell 4: Ask AI for insights
# Select output from Cell 3, then ask:
# "What patterns do you see in this data?"

# Cell 5: Visualization
plt.figure(figsize=(12, 6))
sns.lineplot(data=df, x='date', y='revenue')
plt.title('Revenue Over Time')
plt.show()