diff options
Diffstat (limited to 'book/module1')
| -rw-r--r-- | book/module1/1_excel_to_python.tex | 119 | ||||
| -rw-r--r-- | book/module1/array.tex | 3 | ||||
| -rw-r--r-- | book/module1/intro_to_anaconda.tex | 16 | ||||
| -rw-r--r-- | book/module1/module1.tex | 22 | ||||
| -rw-r--r-- | book/module1/spyder_getting_started.tex | 8 |
5 files changed, 143 insertions, 25 deletions
diff --git a/book/module1/1_excel_to_python.tex b/book/module1/1_excel_to_python.tex new file mode 100644 index 0000000..300c951 --- /dev/null +++ b/book/module1/1_excel_to_python.tex @@ -0,0 +1,119 @@ +\section{Excel to Python}\label{excel-to-python} + +\begin{itemize} +\tightlist +\item + Importing +\item + Plotting +\item + Statistical analysis +\end{itemize} + +\subsection{\texorpdfstring{\textbf{How Excel Translates to +Python}}{How Excel Translates to Python}}\label{how-excel-translates-to-python} + +Here's how common Excel functionalities map to Python: + +\begin{longtable}[]{@{} + >{\raggedright\arraybackslash}p{(\columnwidth - 2\tabcolsep) * \real{0.2911}} + >{\raggedright\arraybackslash}p{(\columnwidth - 2\tabcolsep) * \real{0.7089}}@{}} +\toprule\noalign{} +\begin{minipage}[b]{\linewidth}\raggedright +\textbf{Excel Feature} +\end{minipage} & \begin{minipage}[b]{\linewidth}\raggedright +\textbf{Python Equivalent} +\end{minipage} \\ +\midrule\noalign{} +\endhead +\bottomrule\noalign{} +\endlastfoot +Formulas (SUM, AVERAGE) & \texttt{numpy}, \texttt{pandas} +(\texttt{df.sum()}, \texttt{df.mean()}) \\ +Sorting \& Filtering & \texttt{pandas.sort\_values()}, +\texttt{df{[}df{[}\textquotesingle{}col\textquotesingle{}{]}\ \textgreater{}\ value{]}} \\ +Conditional Formatting & \texttt{matplotlib} for highlighting \\ +Pivot Tables & \texttt{pandas.pivot\_table()} \\ +Charts \& Graphs & \texttt{matplotlib}, \texttt{seaborn}, +\texttt{plotly} \\ +Regression Analysis & \texttt{scipy.stats.linregress}, +\texttt{sklearn.linear\_model} \\ +Solver/Optimization & \texttt{scipy.optimize} \\ +VBA Macros & Python scripting with \texttt{openpyxl}, \texttt{pandas}, +or \texttt{xlwings} \\ +\end{longtable} + +\subsection{Statistical functions}\label{statistical-functions} + +\paragraph{SUM}\label{sum} + +Built-in: + +\begin{Shaded} +\begin{Highlighting}[] +\NormalTok{my\_array }\OperatorTok{=}\NormalTok{ [}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{3}\NormalTok{, }\DecValTok{4}\NormalTok{, }\DecValTok{5}\NormalTok{]} +\NormalTok{total }\OperatorTok{=} \BuiltInTok{sum}\NormalTok{(my\_array)} +\BuiltInTok{print}\NormalTok{(total) }\CommentTok{\# Output: 15} +\end{Highlighting} +\end{Shaded} + +Numpy: + +\begin{Shaded} +\begin{Highlighting}[] +\ImportTok{import}\NormalTok{ numpy }\ImportTok{as}\NormalTok{ np} + +\NormalTok{my\_array }\OperatorTok{=}\NormalTok{ np.array([}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{3}\NormalTok{, }\DecValTok{4}\NormalTok{, }\DecValTok{5}\NormalTok{])} +\NormalTok{total }\OperatorTok{=}\NormalTok{ np.}\BuiltInTok{sum}\NormalTok{(my\_array)} +\BuiltInTok{print}\NormalTok{(total) }\CommentTok{\# Output: 15} +\end{Highlighting} +\end{Shaded} + +\subsubsection{Average}\label{average} + +Built-in: + +\begin{Shaded} +\begin{Highlighting}[] +\NormalTok{my\_array }\OperatorTok{=}\NormalTok{ [}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{3}\NormalTok{, }\DecValTok{4}\NormalTok{, }\DecValTok{5}\NormalTok{]} +\NormalTok{average }\OperatorTok{=} \BuiltInTok{sum}\NormalTok{(my\_array) }\OperatorTok{/} \BuiltInTok{len}\NormalTok{(my\_array)} +\BuiltInTok{print}\NormalTok{(average) }\CommentTok{\# Output: 3.0} +\end{Highlighting} +\end{Shaded} + +Numpy: + +\begin{Shaded} +\begin{Highlighting}[] +\ImportTok{import}\NormalTok{ numpy }\ImportTok{as}\NormalTok{ np} + +\NormalTok{my\_array }\OperatorTok{=}\NormalTok{ np.array([}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{3}\NormalTok{, }\DecValTok{4}\NormalTok{, }\DecValTok{5}\NormalTok{])} +\NormalTok{average }\OperatorTok{=}\NormalTok{ np.mean(my\_array)} +\BuiltInTok{print}\NormalTok{(average) }\CommentTok{\# Output: 3.0} +\end{Highlighting} +\end{Shaded} + +\subsection{Plotting}\label{plotting} + +We can use the package \emph{matplotlib} to plot our graphs in python. +Matplotlib provides data visualization tools for the Scientific Python +Ecosystem. You can make very professional looking figures with this +tool. + +Here is a section from the matplotlib documentation page that you can +run in python. + +\begin{Shaded} +\begin{Highlighting}[] +\ImportTok{import}\NormalTok{ matplotlib.pyplot }\ImportTok{as}\NormalTok{ plt} + +\NormalTok{fig, ax }\OperatorTok{=}\NormalTok{ plt.subplots() }\CommentTok{\# Create a figure containing a single Axes.} +\NormalTok{ax.plot([}\DecValTok{1}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{3}\NormalTok{, }\DecValTok{4}\NormalTok{], [}\DecValTok{1}\NormalTok{, }\DecValTok{4}\NormalTok{, }\DecValTok{2}\NormalTok{, }\DecValTok{3}\NormalTok{]) }\CommentTok{\# Plot some data on the Axes.} +\NormalTok{plt.show() }\CommentTok{\# Show the figure.} +\end{Highlighting} +\end{Shaded} + +Check out the documentation pages for a +\href{https://matplotlib.org/stable/users/explain/quick_start.html\#a-simple-example}{simple +example} or more information on the types of plots you came create +\href{https://matplotlib.org/stable/plot_types/index.html}{here}. diff --git a/book/module1/array.tex b/book/module1/array.tex index db176e7..c9fc302 100644 --- a/book/module1/array.tex +++ b/book/module1/array.tex @@ -40,8 +40,7 @@ would be stress. \item From \href{https://numpy.org/doc/2.2/user/absolute_beginners.html}{Numpy - documentation} - \includegraphics{https://www.mathworks.com/help/examples/matlab/win64/nddemo_02.gif} + documentation} \includegraphics{figures/multi-dimensional-array.gif} \end{itemize} If the load on this block changes over time, then we may want to add a diff --git a/book/module1/intro_to_anaconda.tex b/book/module1/intro_to_anaconda.tex index bc548c9..935b3f5 100644 --- a/book/module1/intro_to_anaconda.tex +++ b/book/module1/intro_to_anaconda.tex @@ -7,10 +7,10 @@ write our python code. The Anaconda website nicely describes \emph{Navigator} as: -a graphical user interface (GUI) that enables you to work with packages -and environments without needing to type conda commands in a terminal -window.Find the packages you want, install them in an environment, run -the packages, and update them -- all inside Navigator. +\emph{a graphical user interface (GUI) that enables you to work with +packages and environments without needing to type conda commands in a +terminal window.Find the packages you want, install them in an +environment, run the packages, and update them -- all inside Navigator.} To better understand how Navigator works and interacts with the anaconda ecosystem see the figure below. @@ -63,7 +63,7 @@ environment for us to use Spyder with. \begin{figure} \centering -\includegraphics{https://mintlify.s3.us-west-1.amazonaws.com/anaconda-29683c67/images/nav-env-labeled.png} +\includegraphics{figures/anaconda_environment_page.png} \caption{Environment Page} \end{figure} @@ -77,7 +77,7 @@ environment for us to use Spyder with. \begin{figure} \centering -\includegraphics{https://mintlify.s3.us-west-1.amazonaws.com/anaconda-29683c67/images/nav-getting-started-create.png} +\includegraphics{figures/anaconda_create_new_environment.png} \caption{Create new environment} \end{figure} @@ -117,7 +117,7 @@ library we will be using for this class. \begin{figure} \centering -\includegraphics{https://mintlify.s3.us-west-1.amazonaws.com/anaconda-29683c67/images/nav-pkg-list.png} +\includegraphics{figures/anaconda_select_package_to_manage.png} \caption{Select environment to manage} \end{figure} @@ -177,7 +177,7 @@ other applications. \begin{figure} \centering -\includegraphics{https://mintlify.s3.us-west-1.amazonaws.com/anaconda-29683c67/images/nav-tabs.png} +\includegraphics{figures/anaconda_homepage.png} \caption{Anaconda Home Page} \end{figure} diff --git a/book/module1/module1.tex b/book/module1/module1.tex index 58db30b..6ed476b 100644 --- a/book/module1/module1.tex +++ b/book/module1/module1.tex @@ -1,16 +1,16 @@ -\chapter{Module 1} -\input{module1/array} -\input{module1/arrays} +\chapter{Module 1: Introductory Programming Concepts} +\input{module1/intro_to_programming} +\input{module1/installing_anaconda} +\input{module1/intro_to_anaconda} +\input{module1/jupyter_lab_notebook} +\input{module1/spyder_getting_started} \input{module1/basics_of_python} -\input{module1/classes_and_objects} -\input{module1/computational_expense} -\input{module1/computing_fundamentals} +\input{module1/array} \input{module1/control_structures} \input{module1/functions} +\input{module1/classes_and_objects} \input{module1/fundamentals_of_programming} -\input{module1/installing_anaconda} -\input{module1/intro_to_anaconda} -\input{module1/intro_to_programming} -\input{module1/jupyter_lab_notebook} +\input{module1/computing_fundamentals} \input{module1/open_source_software} -\input{module1/spyder_getting_started} +\input{module1/1_excel_to_python} +\input{module1/computational_expense} diff --git a/book/module1/spyder_getting_started.tex b/book/module1/spyder_getting_started.tex index d1e20fe..70a3d41 100644 --- a/book/module1/spyder_getting_started.tex +++ b/book/module1/spyder_getting_started.tex @@ -14,7 +14,7 @@ Using Anaconda we will select the environment we created earlier \begin{figure} \centering -\includegraphics{https://docs.spyder-ide.org/current/_images/mainwindow_default_1610.png} +\includegraphics{figures/spyder_interface.png} \caption{Spyder Interface} \end{figure} @@ -29,7 +29,7 @@ This pane is used to write your scripts. The \begin{figure} \centering -\includegraphics{https://docs.spyder-ide.org/5/_images/editor-components.png} +\includegraphics{figures/editor_key_components.png} \caption{Editor key components} \end{figure} @@ -65,7 +65,7 @@ computations, assign and modify variables. \begin{figure} \centering -\includegraphics{https://docs.spyder-ide.org/5/_images/console-standard.png} +\includegraphics{figures/spyder_ipython_console.png} \caption{IPython Console} \end{figure} @@ -100,6 +100,6 @@ you to inspect the data in a spreadsheet like view. \begin{figure} \centering -\includegraphics{https://docs.spyder-ide.org/5/_images/variable-explorer-standard.png} +\includegraphics{figures/spyder_variable_explorer.png} \caption{Variable Explorer} \end{figure} |
