# The data_path variable's string can be changed to the path where you have the data set you wish to load.ĭata_path = 'C:/Users/Aaron/Google_Drive/Projects/Python_R_Data_Analysis/Python/Ginzberg.csv' # The next line will load xlwings and open the workbookįrom xlwings import Range, Workbook, Chart Workbook = 'C:/Users/Aaron/Google_Drive/Projects/Python_R_Data_Analysis/Python/Linear_Regression_Workbook.xlsx' # To load the Linear Regression Workbook, simply change the workbook variable's string to where you have the workbook saved. # First, we will load all the required packages
# If you'd like to learn more about linear regression, feel free to check out my Linear Regression with Python notebook
While I wasn't able to build an Excel-only method for linear regression (other than using the dreadful LINEST function), one could quickly run through the notebook and be given a linear regression model using Python. # However, I revised the process to allow other users to simply change the paths of the Regression Workbook and the data to be able to do the same analysis. # Because of these limitations, I decided to use an IPython Notebook for creating and fitting linear regression models and printing the results to Excel to share for those who use Excel exclusively and those who don't want to bother installing Python and/or using the Notebook (something I run into frequently in my current position). xlsx format, the data is copied in with additional headers and causes the actual column names to shift down one. # The second issue I came across taking data from the Data tab of the Excel workbook and loading it to process with Pandas. The package xlrd contains an Image object, but it only works on bitmap files. One issue was I wanted to take the plot images generated and copy them into the Excel sheet however, I wasn't able to find a way to accomplish this. # During the process, I ran into several hurdles. # To accomplish this, I used statsmodels, pandas and xlwings. I also wanted to give a nice summary of the model statistics for users to determine the goodness-of-fit of the model.
# After working through a linear regression example using Python, I wanted to see if it was possible to create an Excel front-end and allow users to load their own datasets, set their parameters, fit a model, and get predictions based on the model, without having to code anything.