Excel to Python: A Transition Guide
Already comfortable with Excel? Learn how your spreadsheet skills translate directly to Python and Pandas.
Already comfortable with Excel? Learn how your spreadsheet skills translate directly to Python and Pandas.
Get full access to all Data Science, Machine Learning, and AI courses built for finance professionals.
One-time payment - Lifetime access
Or create a free account to start
A step-by-step guide covering Python, SQL, analytics, and finance applications.
Or create a free account to access more
Get full access to all Data Science, Machine Learning, and AI courses built for finance professionals.
One-time payment - Lifetime access
Or create a free account to start
A step-by-step guide covering Python, SQL, analytics, and finance applications.
Or create a free account to access more
If you are comfortable with Excel, you are already halfway to learning Python for data analysis. This guide shows you how your existing skills translate.
Excel is great, but Python offers:
Pandas is Python's answer to Excel. A DataFrame is essentially a spreadsheet.
1import pandas as pd
2
3# Read Excel file
4df = pd.read_excel('sales_data.xlsx')
5
6# Or read CSV
7df = pd.read_csv('sales_data.csv')
8| Excel | Python |
|---|---|
| Scroll through sheet | df.head() - first 5 rows |
| Ctrl+End | df.shape - (rows, columns) |
| Look at columns | df.columns |
| Excel | Python |
|---|---|
| Click column A | df['A'] or df.A |
| Select A and B | df[['A', 'B']] |
| Row 5 | df.iloc[4] (0-indexed) |
| A1:B10 | df.loc[0:9, ['A', 'B']] |
| Excel | Python |
|---|---|
| Filter > Greater than 100 | df[df['Sales'] > 100] |
| Filter > Text contains "NY" | df[df['City'].str.contains('NY')] |
| Multiple conditions | df[(df['Sales'] > 100) & (df['Region'] == 'East')] |
| Excel | Python |
|---|---|
| =SUM(A:A) | df['A'].sum() |
| =AVERAGE(A:A) | df['A'].mean() |
| =MAX(A:A) | df['A'].max() |
| =COUNT(A:A) | df['A'].count() |
| =COUNTIF(A:A, ">100") | (df['A'] > 100).sum() |
Excel: New column with formula =A1*B1
Python:
df['Total'] = df['Price'] * df['Quantity']
Excel: =VLOOKUP(A1, Sheet2!A:B, 2, FALSE)
Python:
result = pd.merge(df1, df2, on='ID', how='left')
Excel: Insert > PivotTable
Python:
1pivot = df.pivot_table(
2 values='Sales',
3 index='Region',
4 columns='Product',
5Excel: Data > Subtotal
Python:
1df.groupby('Region')['Sales'].sum()
2
3# Multiple aggregations
4df.groupby('Region'Let's analyze sales data - something you would do in Excel:
1import pandas as pd
2
3# Load data
4df = pd.read_excel('sales.xlsx')
5
6