Forum Discussion
python for excel : python packages
- Sep 25, 2023Hi Leon,
Thanks for your guide, I have tried xlwings library, as I thought it may also be benefit from quick runtime by the help of jupyter notebook, the sync between is really quick so far, will try more cases with more work book open. Thanks!
As of my last update in January 2022, Excel's Python integration primarily supports a limited set of libraries like pandas, seaborn, scikit-learn, and matplotlib. However, you cannot directly install or include additional Python packages, such as NumPy-Financial, within Excel's integrated Python environment.
Workarounds:
External Python Environment: You can use an external Python environment to run your code with the desired packages and then import the results into Excel using methods like data import or linking to external data sources.
Custom Functions with Excel-DNA: If you are comfortable with .NET development, you can create custom Excel functions using Excel-DNA that leverage the full capabilities of Python, including any package you want to use.
Excel Add-ins: Consider creating an https://statsidea.com/excel-learn-how-to-develop-chart-forget-about-deserted-axis-labels/ Add-in using technologies like VBA or .NET that integrates with an external Python script. This approach allows you to utilize any Python package and seamlessly interact with Excel.
Power Query: For data manipulation tasks, you can use Power Query to connect to external data sources, including Python scripts, and then load the data into Excel.
Python API Calls: If the package provides an API or web service, you can make API calls directly from Excel using VBA or Power Query to retrieve and manipulate the data.
Example with Power Query:
You can use Power Query to run a Python script and fetch the data into Excel.
- Go to Data > Get Data > From Other Sources > Blank Query.
- In the formula bar, enter your Python script using the Python.Execute function.
let Source = Python.Execute("import numpy_financial as npf; data = [100, 200, 300]; result = npf.npv(0.05, data); result") in Source
Conclusion:
While Excel's built-in Python integration has limitations on supported packages, you can leverage various workarounds to use additional Python packages in combination with Excel. Choose the approach that best fits your needs and technical expertise.
- SergeiBaklanApr 20, 2024Diamond Contributor
Python.Execute is not available in Power Query for Excel, that's in Power BI Desktop.