Python in Excel initialization settings
Applies To
Python in Excel is available to Enterprise and Business users running the Current Channel on Windows, starting with Version 2408 (Build 17928.20114), and Monthly Enterprise Channel on Windows, starting with Version 2408 (Build 17928.20216). It's also available in Excel on the web for Enterprise and Business users. Python in Excel is available in preview for Family and Personal users in Excel on the web or running the Current Channel on Windows starting with Version 2405 (Build 17628.20164). It's available in preview for Education users running the Current Channel (Preview) through the Microsoft 365 Insider Program. It's not currently available for the Semi-Annual Enterprise Channel.
Python in Excel is available to Enterprise and Business users running the Current Channel on Excel for Mac starting with Version 16.96 (Build 25041326). It's available in preview for Family and Personal users on Excel for Mac through the Microsoft 365 Insider Program. Choose the Beta Channel Insider level and install the latest build of Excel; it's available starting with Version 16.95 (Build 25021921).
For more availability information, see Python in Excel availability. If you encounter any concerns with Python in Excel, please report them by selecting Help > Feedback in Excel.
New to Python in Excel? Start with Introduction to Python in Excel and Get started with Python in Excel.
Initialization settings task pane
Python in Excel offers an initialization settings task pane. This task pane allows you to control and create universal Python settings for a workbook.
The initialization settings in one workbook don't impact the initialization settings in another workbook, even if you have both workbooks open at the same time.
Note: In Python projects on a local machine, initialization settings are commonly saved in a file called init.py. The Python in Excel initialization settings task pane functions similarly to an init.py file.
Access the task pane
To open the initialization settings task pane, go to the Formulas tab and select Initialization in the Python section.
Default settings
The initialization settings task pane includes the following statements and comments by default. Some of these statements are required and should not be removed, and some of the statements are editable. See the following Required settings and Editable settings sections for additional information.
# The following import statements are pre-loaded. import numpy as np import pandas as pd import matplotlib.pyplot as plt import statsmodels as sm import seaborn as sns import excel import warnings warnings.simplefilter('ignore')
# Set default conversions for the xl() function. excel.set_xl_scalar_conversion(excel.convert_to_scalar) excel.set_xl_array_conversion(excel.convert_to_dataframe)
Required settings
The initialization settings task pane contains some statements that are required for Python in Excel to calculate correctly.
Important: Removing the following statements is not recommended. These settings control how Excel runs Python formulas. Removing these statements may cause errors.
import excel import warnings warnings.simplefilter('ignore') excel.set_xl_scalar_conversion(...) excel.set_xl_array_conversion(...)
Editable settings
The initialization settings task pane includes the following import statements for the NumPy, pandas, Matplotlib, statsmodels, and seaborn libraries by default.
import numpy as np import pandas as pd import matplotlib.pyplot as plt import statsmodels as sm import seaborn as sns
You can add import statements for additional libraries and edit or remove these existing open-source library import statements if desired. See Open-source libraries and Python in Excel for information about available libraries.
Note: Changing initialization settings affects how Python behaves in your workbook. Any changes can impact both Python in Excel and Copilot in Excel with Python.