loading-data-from-files/script.rst
changeset 247 81bb9a6d7eeb
parent 217 b595f90016c5
child 248 0bad7228029c
equal deleted inserted replaced
246:95e7682e9d43 247:81bb9a6d7eeb
     1 ========
     1 .. Objectives
     2  Script
     2 .. ----------
     3 ========
       
     4 
     3 
     5 Welcome to this tutorial on loading data from files. 
     4 .. At the end of this tutorial, you will be able to
       
     5 
       
     6 .. + Read data from files, containing a single column of data using the
       
     7 ..   ``loadtxt`` command.
       
     8 .. + Read multiple columns of data, separated by spaces or other
       
     9 ..   delimiters.
       
    10 
       
    11 
       
    12 .. Prerequisites
       
    13 .. -------------
       
    14 
       
    15 .. 1. getting started with ``ipython``
       
    16      
       
    17 .. Author              : 
       
    18    Internal Reviewer   : 
       
    19    External Reviewer   :
       
    20    Checklist OK?       : <put date stamp here, if OK> [2010-10-05]
       
    21 
       
    22 Script
       
    23 ------
       
    24 
       
    25 {{{ Show the slide containing title }}}
       
    26 
       
    27 Hello Friends. Welcome to this tutorial on loading data from files.
     6 
    28 
     7 {{{ Screen shows welcome slide }}}
    29 {{{ Screen shows welcome slide }}}
     8 
    30 
     9 We often require to plot points obtained from experimental
    31 We often require to plot points obtained from experimental
    10 observations. In this tutorial we shall learn to read data from files
    32 observations. In this tutorial we shall learn to read data from files
    59 Now, let us use the ``loadtxt`` command to read a file that contains
    81 Now, let us use the ``loadtxt`` command to read a file that contains
    60 two columns of data, ``pendulum.txt``. This file contains the length
    82 two columns of data, ``pendulum.txt``. This file contains the length
    61 of the pendulum in the first column and the corresponding time period
    83 of the pendulum in the first column and the corresponding time period
    62 in the second.
    84 in the second.
    63 
    85 
    64 %%1%% Pause the video here, and use the ``cat`` command to view the
    86 .. Following is an exercise that you must do. 
    65 contents of this file and then resume the video.
    87 
       
    88 .. %%1%% Use the ``cat`` command to view the contents of this file.
       
    89 
       
    90 .. Please, pause the video here. Do the exercise and then continue. 
    66 
    91 
    67 This is how we look at the contents of the file, ``pendulum.txt``
    92 This is how we look at the contents of the file, ``pendulum.txt``
    68 ::
    93 ::
    69 
    94 
    70   cat /home/fossee/pendulum.txt
    95   cat /home/fossee/pendulum.txt
   114 
   139 
   115 In this tutorial, we have learnt the basic use of the ``loadtxt``
   140 In this tutorial, we have learnt the basic use of the ``loadtxt``
   116 command, which is capable of doing a lot more than we have used it for
   141 command, which is capable of doing a lot more than we have used it for
   117 until now, for example
   142 until now, for example
   118 
   143 
   119 %%2%% Pause the video here, and read the file
   144 Following is an exercise that you must do. 
   120 ``pendulum_semicolon.txt`` which contains the same data as
   145 
   121 ``pendulum.txt``, but the columns are separated by semi-colons instead
   146 %%1%% Read the file ``pendulum_semicolon.txt`` which contains the same
   122 of spaces. Use the IPython help to see how to do this. Once you have
   147 data as ``pendulum.txt``, but the columns are separated by semi-colons
   123 finished, resume the video to look at the solution.
   148 instead of spaces. Use the IPython help to see how to do this. 
       
   149 
       
   150 Please, pause the video here. Do the exercise and then continue. 
   124 
   151 
   125 {{{ switch back to the terminal }}}
   152 {{{ switch back to the terminal }}}
   126 ::
   153 ::
   127 
   154 
   128   L, T = loadtxt('/home/fossee/pendulum_semicolon.txt', unpack=True, delimiter=';')
   155   L, T = loadtxt('/home/fossee/pendulum_semicolon.txt', unpack=True, delimiter=';')
   140   + Read data from files, containing a single column of data using the
   167   + Read data from files, containing a single column of data using the
   141     ``loadtxt`` command.
   168     ``loadtxt`` command.
   142   + Read multiple columns of data, separated by spaces or other
   169   + Read multiple columns of data, separated by spaces or other
   143     delimiters.
   170     delimiters.
   144 
   171 
   145 Thank you!   
   172 {{{ Show the "sponsored by FOSSEE" slide }}}
   146 
   173 
       
   174 This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India
       
   175 
       
   176 Hope you have enjoyed and found it useful.
       
   177 Thank you!
       
   178