Reading an Excel file in pandas takes one line: pd.read_excel("file.xlsx"). That returns a DataFrame of the first sheet. To choose a different sheet, pass sheet_name="Sheet2" or an index like sheet_name=1. To read every sheet at once, use sheet_name=None, which returns a dictionary of DataFrames keyed by sheet name. The rest of this guide covers the setup, the options that matter, and what to do when the import fails.

What You'll Need

  • Python 3 installed and working from a terminal or command prompt.
  • pandas installed (pip install pandas).
  • An Excel engine installed. pandas delegates the actual file parsing to a separate library. For .xlsx files use openpyxl (pip install openpyxl). For legacy .xls files use xlrd (pip install xlrd). Recent pandas versions no longer bundle these automatically, so install the one that matches your file type.
  • The Excel file saved locally, ideally in the same folder as your script, so you can reference it by a short relative path.

Step-by-Step

  1. Install the packages. In a terminal run pip install pandas openpyxl. If you also need to read old .xls files, add xlrd. If you use a virtual environment, activate it first so the packages land in the right place.
  2. Import pandas. At the top of your script or notebook write import pandas as pd. The pd alias is a convention, not a requirement, but nearly every example you will find uses it.
  3. Point at the file. Decide on the path. A relative path like "data/sales.xlsx" resolves from the folder you run the script in. A raw string with r prefix avoids backslash escaping problems on Windows: r"C:\Users\me\data.xlsx".
  4. Read the first sheet. Call df = pd.read_excel("data/sales.xlsx"). The result is a DataFrame containing the first worksheet. Print df.head() to confirm the columns and values look right.
  5. Select a specific sheet. Pass sheet_name. Use the tab name as a string (sheet_name="Q1") or a zero-based position (sheet_name=0 for the first sheet, 1 for the second). If you are unsure of the names, read with sheet_name=None first and inspect the dictionary keys.
  6. Read all sheets at once. sheets = pd.read_excel("data/sales.xlsx", sheet_name=None) gives you a dict such as {"Q1": df1, "Q2": df2}. You can then loop over sheets.items() or pick one by key.
  7. Handle headers and skipped rows. If the real header is not on row 1, use header=2 (zero-based row index) or header=None to get default integer column names. Use skiprows=3 to drop preamble rows above the table. Use usecols="A:C" or usecols=[0, 2, 5] to load only the columns you need.
  8. Deal with missing values and types. By default pandas converts blank cells to NaN. Pass na_values=["N/A", "-", ""] to treat extra placeholder strings as missing. Use dtype={"Zip": str} to stop pandas from turning a numeric-looking code into a number and losing leading zeros.
  9. Verify the result. Run df.shape, df.columns and df.dtypes. These three checks catch most import surprises before you start analysis.

Common Mistakes

  • Forgetting the engine. Installing pandas but not openpyxl produces an ImportError or a message about a missing optional dependency. Install the engine for your file type.
  • Wrong path. A FileNotFoundError almost always means the working directory is not what you think. Print os.getcwd() or use an absolute path to confirm.
  • Assuming the first sheet is the data. Workbooks often open on a cover or summary tab. Check sheet_name=None and pick deliberately.
  • Losing leading zeros. Part numbers, ZIP codes and phone numbers stored as text can come back as integers. Force string dtype for those columns.
  • Header mismatch. Merged cells and title rows above the table push the real header down. Adjust header and skiprows rather than renaming columns after the fact.

Tips

  • Read a small sample first with nrows=100 to check layout quickly on a large workbook.
  • Use sheet_name=None once to discover exact tab names, then switch to a single-sheet read for speed.
  • If the file changes often, wrap the read in a function so the path, sheet and dtype settings live in one place.
  • For very large workbooks, consider converting to CSV once and reading that with pd.read_csv, which is generally faster.

Troubleshooting

Work through these in order, simplest first.

  1. ModuleNotFoundError for openpyxl or xlrd. Install the missing engine with pip, then restart your Python session so the import picks it up.
  2. FileNotFoundError. Confirm the file exists and the path is correct for your current working directory. Try an absolute path to isolate the issue.
  3. UnicodeDecodeError or garbled text. This usually points to an old or unusual file format. Re-save the file as .xlsx from Excel and read it again.
  4. Empty DataFrame. Check that the sheet name is correct and that header and skiprows are not skipping past the data.
  5. Columns named Unnamed: 0, Unnamed: 1. The header row was not detected. Set header to the correct row index.
  6. Still stuck. Open the file in Excel, confirm the tab names and the first populated row, then match those to your read call.

Frequently Asked Questions

Can pandas read .xls files?

Yes, with the xlrd engine installed. Newer pandas versions require it explicitly for legacy .xls files, while .xlsx uses openpyxl.

How do I read only one column?

Pass usecols=["ColumnName"] or a letter range like usecols="B". This loads just that column and is faster on wide sheets.

Why are my numbers stored as text?

Excel may store them as text, or pandas may have inferred a type you did not expect. Check df.dtypes and pass an explicit dtype mapping when reading.

Can I read a password-protected workbook?

Not directly with a plain read_excel call. Remove the password in Excel first, or use a library that supports decryption, then hand the decrypted file to pandas.

How do I read every sheet in a workbook?

Use sheet_name=None. The result is a dictionary of DataFrames keyed by sheet name, which you can iterate over.

Does read_excel work with Google Sheets?

Only after you download or export the sheet as an .xlsx file. pandas reads local files and URLs, not Google Sheets directly.