day1/session3.tex
changeset 379 682b6f66fe11
parent 378 2299700a8b97
child 382 41c34770d63a
equal deleted inserted replaced
378:2299700a8b97 379:682b6f66fe11
    71 %    postbreak = \space\dots
    71 %    postbreak = \space\dots
    72 % }
    72 % }
    73 
    73 
    74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    74 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
    75 % Title page
    75 % Title page
    76 \title[Statistics]{Python for Science and Engg: Statistics}
    76 \title[Statistics]{Python for Scienc and Engg: Statistics}
    77 
    77 
    78 \author[FOSSEE] {FOSSEE}
    78 \author[FOSSEE] {FOSSEE}
    79 
    79 
    80 \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
    80 \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay}
    81 
    81 
   150   ....     g = 4 * pi * pi * l / (t * t)
   150   ....     g = 4 * pi * pi * l / (t * t)
   151   ....     g_list.append(g)
   151   ....     g_list.append(g)
   152   \end{lstlisting}
   152   \end{lstlisting}
   153 \end{frame}
   153 \end{frame}
   154 
   154 
   155 \begin{frame}
   155 \begin{frame}[fragile]
   156   \frametitle{Computing mean ``g''}
   156   \frametitle{Mean ``g'' - Classical method}
   157   \begin{block}{Exercise}
       
   158     Obtain the mean of ``g''
       
   159   \end{block}
       
   160 \end{frame}
       
   161 
       
   162 \begin{frame}[fragile]
       
   163   \frametitle{Mean ``g''}
       
   164   \begin{lstlisting}
   157   \begin{lstlisting}
   165 In []: total = 0
   158 In []: total = 0
   166 In []: for g in g_list:
   159 In []: for g in g_list:
   167  ....:     total += g
   160  ....:     total += g
   168  ....:
   161  ....:
   171 In []: print 'Mean: ', g_mean
   164 In []: print 'Mean: ', g_mean
   172   \end{lstlisting}
   165   \end{lstlisting}
   173 \end{frame}
   166 \end{frame}
   174 
   167 
   175 \begin{frame}[fragile]
   168 \begin{frame}[fragile]
   176   \frametitle{Mean ``g''}
   169   \frametitle{Mean ``g'' - Slightly improved method}
   177   \begin{lstlisting}
   170   \begin{lstlisting}
   178 In []: g_mean = sum(g_list) / len(g_list)
   171 In []: g_mean = sum(g_list) / len(g_list)
   179 In []: print 'Mean: ', g_mean
   172 In []: print 'Mean: ', g_mean
   180   \end{lstlisting}
   173   \end{lstlisting}
   181 \end{frame}
   174 \end{frame}
   182 
   175 
   183 \begin{frame}[fragile]
   176 \begin{frame}[fragile]
   184   \frametitle{Mean ``g''}
   177   \frametitle{Mean ``g'' - One liner}
   185   \begin{lstlisting}
   178   \begin{lstlisting}
   186 In []: g_mean = mean(g_list)
   179 In []: g_mean = mean(g_list)
   187 In []: print 'Mean: ', g_mean
   180 In []: print 'Mean: ', g_mean
   188   \end{lstlisting}
   181   \end{lstlisting}
   189   \inctime{10}
   182   \inctime{10}
   213   Each record consists of:
   206   Each record consists of:
   214   \begin{itemize}
   207   \begin{itemize}
   215     \item Region Code
   208     \item Region Code
   216     \item Roll Number
   209     \item Roll Number
   217     \item Name
   210     \item Name
   218     \item Marks of 5 subjects: English, Hindi, Maths, Science, Social
   211     \item Marks of 5 subjects: SLang, Flang Maths, Science, Social
   219     \item Total marks
   212     \item Total marks
   220     \item Pass/Fail (P/F)
   213     \item Pass/Fail (P/F)
   221     \item Withheld (W)
   214     \item Withheld (W)
   222   \end{itemize}
   215   \end{itemize}
   223   \inctime{5}
   216   \inctime{5}
   255 \end{frame}
   248 \end{frame}
   256 
   249 
   257 \subsection{Data processing}
   250 \subsection{Data processing}
   258 \begin{frame}[fragile]
   251 \begin{frame}[fragile]
   259   \frametitle{File reading and parsing \ldots}
   252   \frametitle{File reading and parsing \ldots}
       
   253 \emphbar{Reading files line by line is the same as we had done with the pendulum example.}
       
   254 
   260   \begin{lstlisting}
   255   \begin{lstlisting}
   261 for record in open('sslc1.txt'):
   256 for record in open('sslc1.txt'):
   262     fields = record.split(';')
   257     fields = record.split(';')
   263   \end{lstlisting}
   258   \end{lstlisting}
   264 \begin{block}{}
       
   265 \centerline{Recall pendulum example!}
       
   266 \end{block}
       
   267 \end{frame}
   259 \end{frame}
   268 
   260 
   269 \subsection{Dictionaries}
   261 \subsection{Dictionaries}
   270 \begin{frame}[fragile]
   262 \begin{frame}[fragile]
   271   \frametitle{Dictionaries: Introduction}
   263   \frametitle{Dictionaries: Introduction}
   272   \begin{itemize}
   264   \begin{itemize}
   273     \item lists index: 0 \ldots n
   265     \item Lists index using integers\\
   274     \item dictionaries index using strings
   266 Recall \typ{p = [2, 3, 5, 7]} and\\
       
   267 \typ{p[1]} is equal to \typ{3}
       
   268     \item Dictionaries index using strings
   275   \end{itemize}
   269   \end{itemize}
   276 \end{frame}
   270 \end{frame}
   277 
   271 
   278 \begin{frame}[fragile]
   272 \begin{frame}[fragile]
   279   \frametitle{Dictionaries \ldots}
   273   \frametitle{Dictionaries \ldots}
   280   \begin{lstlisting}
   274   \begin{lstlisting}
   281 In []: d = {'jpg' : 'image file',
   275 In []: d = {'png' : 'image file',
   282       'txt' : 'text file', 
   276       'txt' : 'text file', 
   283       'py' : 'python code'}
   277       'py' : 'python code'
       
   278       'java': 'bad code', 
       
   279       'cpp': 'complex code'}
   284 
   280 
   285 In []: d['txt']
   281 In []: d['txt']
   286 Out[]: 'text file'
   282 Out[]: 'text file'
   287   \end{lstlisting}
   283   \end{lstlisting}
   288 \end{frame}
   284 \end{frame}
   291   \frametitle{Dictionaries \ldots}
   287   \frametitle{Dictionaries \ldots}
   292   \begin{lstlisting}
   288   \begin{lstlisting}
   293 In []: 'py' in d
   289 In []: 'py' in d
   294 Out[]: True
   290 Out[]: True
   295 
   291 
   296 In []: 'cpp' in d
   292 In []: 'jpg' in d
   297 Out[]: False
   293 Out[]: False
   298   \end{lstlisting}
   294   \end{lstlisting}
   299 \end{frame}
   295 \end{frame}
   300 
   296 
   301 \begin{frame}[fragile]
   297 \begin{frame}[fragile]
   363 print science.values()
   359 print science.values()
   364   \end{lstlisting}
   360   \end{lstlisting}
   365 \end{frame}
   361 \end{frame}
   366 
   362 
   367 \subsection{Visualizing data}
   363 \subsection{Visualizing data}
       
   364 \begin{frame}[fragile]
       
   365   \frametitle{Pie Chart}
       
   366   \begin{lstlisting}
       
   367     pie(science.values())
       
   368   \end{lstlisting}
       
   369 \includegraphics[height=2in, interpolate=true]{data/science_nolabel}
       
   370 \end{frame}
       
   371 
   368 \begin{frame}[fragile]
   372 \begin{frame}[fragile]
   369   \frametitle{Pie chart}
   373   \frametitle{Pie chart}
   370   \small
   374   \small
   371   \begin{lstlisting}
   375   \begin{lstlisting}
   372 pie(science.values(), 
   376 pie(science.values(), 
   404     math_scores.append(score)
   408     math_scores.append(score)
   405   \end{lstlisting}
   409   \end{lstlisting}
   406 \end{frame}
   410 \end{frame}
   407 
   411 
   408 \subsection{Obtaining statistics}
   412 \subsection{Obtaining statistics}
   409 \begin{frame}[fragile]
       
   410   \frametitle{Obtaining statistics}
       
   411   \begin{block}{Exercise}
       
   412     Obtain the mean of Math scores
       
   413   \end{block}
       
   414 \end{frame}
       
   415 
       
   416 \begin{frame}[fragile]
   413 \begin{frame}[fragile]
   417   \frametitle{Obtaining statistics}
   414   \frametitle{Obtaining statistics}
   418   \begin{lstlisting}
   415   \begin{lstlisting}
   419 print 'Mean: ', mean(math_scores)
   416 print 'Mean: ', mean(math_scores)
   420 
   417