Try python for excel developers - book 1
www.hedaro.com
Excel is probably the most popular data analysis tool in the market and most people, including myself, started their data career working with Excel. This book is for the casual Microsoft Excel user that is interested in learning Python. Python is gaining a lot of ground and becoming the go-to software for data analysis. If you are not a programmer or even an engineer, then this book has been created just for you. The examples below will assume you have never programmed before and will try to mimic similar tasks you would normally perform using Excel. Step-by-step instructions are provided and the examples are short so you can read this book in one sitting. After reading the book you should be able to perform a lot of the data analysis you do in Excel but using Python instead. Enjoy!
What Will you Learn:
How to import Python libraries
How to create data using Pandas
How to create new columns
How to sum horizontally
How to compute averages
How to calculate percentages
How to sort data
How to filter data
How to create plots and charts using MatPlotLib
2. Preface
Excel is probably the most popular data analysis tool in the market and most people, including myself,
started their data career working with Excel. This book is for the casual Microsoft Excel user that is
interested in learning Python. Python is gaining a lot of ground and becoming the go-to software for
data analysis. If you are not a programmer or even an engineer, then this book has been created just for
you. The examples below will assume you have never programmed before and will try to mimic similar
tasks you would normally perform using Excel. Step-by-step instructions are provided and the examples
are short so you can read this book in one sitting. After reading the book you should be able to perform
a lot of the data analysis you do in Excel but using Python instead. Enjoy!
3. What you need for this book
• An up-to-date laptop or desktop
• A web browser (such as Chrome) installed on that laptop or desktop
• An internet connection
• A computer with Python 3 installed, including the following libraries: Pandas and Matplotlib
If you have not or do not know how to install Python, I recommend you start with Try Python – for
Beginners before attempting to continue.
4. Introduction
If you are going to work with data, then the Python library you will be working with is called Pandas. For
plotting your data, the go-to library is called Matplotlib. Don’t worry if you do not understand what a
library is, just remember that when you hear the word Pandas, think of data analysis (not a cuddly black
and white panda bear eating bamboo shoots). When you hear the work Matplotlib, think about charts
and plots. The rest of the book will cover specific examples that are commonly performed in a
spreadsheet. Are you ready to get started?
5. Import Libraries
The first lines of code we are going to write are simply to import the libraries that were mentioned in
the introduction; that is Pandas and Matplotlib. At this point please start up a new Jupyter Notebook
and make sure you are programming in Python 3 and not Python 2. If you have no idea what a Jupyter
Notebook is then please start with Try Python – for Beginners or do some Googling. After you have a
notebook running on your computer, type the code in the figure below.
Jupyter Notebook
6. LINE 01
# Import libraries
In Line one, we started with a pound (#) sign. This is how we write comments in Python. We simply type
a pound (#) sign and anything we write after it will be ignored by Python. You can use comments to
write little notes to yourself so that you can remember what in the world the code you wrote means. Try
it for yourself and see how easy it is.
7. LINE 02
Import pandas as pd
In line 2, we tell Python to import the library called Pandas and give it a nickname of “pd.”
9. LINE 04
Import sys
In line 4, we import the SYS module that comes with Python. The only reason we did this is to print the
version of Python I am using for this book.
10. LINE 05
%matplotlib inline
Now, line 5 is a bit tricky. This line basically turns on plotting for the Jupyter Notebook. If we did not add
this line, then our plots will not show up. I know this is a little odd, but just remember that we need to
include this line of code in order for our plots to show up.
Note that all we have done until this point is tell Python we want to use the libraries called Pandas and
Matplotlib.
11. LINE 07, 08, 09
Print(‘Python Version: ‘ + sys.version)
Print(‘Pandas Version: ‘ + pd.__version__)
Print(‘Matplotlib Version: ‘ + mpl.__version__)
In line 7, 8, and 9, we use the PRINT function to print some information on the screen. This information
is simply to make you aware of the version of Python, Pandas, and Matplotlib I am using for this book.