How to Work with an Excel Spreadsheet in Python

How to Work with an Excel Spreadsheet in Python

For those still working with Excel spreadsheets, here's a quick tip ...

To easily work with data from an Excel spreadsheet in Python, use the Pandas library. First, import the spreadsheet, then iterate over the data, using itertuples, like so:

# Install - pip install pandas
import pandas as pd

# Import Excel spreadsheet
df = pd.read_excel("data/excel/device_data.xlsx")

# Iterate over Excel data
for row in df.itertuples():
    print(f"{row.device} | {row.version}")
# Output:
# spine1-nxos | 9.3.7
# spine2-nxos | 9.3.7
# ...

Subscribe to our newsletter and stay updated.

Don't miss anything. Get all the latest posts delivered straight to your inbox.
Great! Check your inbox and click the link to confirm your subscription.
Error! Please enter a valid email address!