diff options
author | Nishanth Amuluru | 2010-09-23 11:54:36 +0530 |
---|---|---|
committer | Nishanth Amuluru | 2010-09-23 11:54:36 +0530 |
commit | d0b50b68312d7be4a35cf2a58bfbcb2394282e2b (patch) | |
tree | 5e6990efb302c6567220fb93a936e9da213f66d7 | |
parent | 044912faff8be00b894c3951451a779013ce6495 (diff) | |
download | st-scripts-d0b50b68312d7be4a35cf2a58bfbcb2394282e2b.tar.gz st-scripts-d0b50b68312d7be4a35cf2a58bfbcb2394282e2b.tar.bz2 st-scripts-d0b50b68312d7be4a35cf2a58bfbcb2394282e2b.zip |
reviewed loading_data_from_files
-rw-r--r-- | loading-data-from-files.rst | 30 | ||||
-rw-r--r-- | progress.org | 2 |
2 files changed, 27 insertions, 5 deletions
diff --git a/loading-data-from-files.rst b/loading-data-from-files.rst index 04d6505..5196619 100644 --- a/loading-data-from-files.rst +++ b/loading-data-from-files.rst @@ -12,8 +12,10 @@ plotting them, against another sequence of points. But, this is not what we do most often. We often require to plot points obtained from experimental observations. -#[punch: the initial part of the paragraph may be removed, to make -this a more generic LO?] +.. #[punch: the initial part of the paragraph may be removed, to make + this a more generic LO?] + +.. #[Nishanth]: The paragraph can be removed. In this tutorial we shall learn to read data from files and save it into sequences that can later be used to plot. @@ -24,6 +26,9 @@ We shall use the ``loadtxt`` command to load data from files. We will be looking at how to get multiple columns of data into multiple sequences. +.. #[Nishanth]: can be "How to read a file with multiple columns of + data and load each column of data into a sequence." + {{{ switch back to the terminal }}} As usual, let us start IPython, using @@ -35,7 +40,7 @@ Now, Let us begin with reading the file primes.txt, which contains just a list of primes listed in a column, using the loadtxt command. The file, in our case, is present in ``/home/fossee/primes.txt``. -#[punch: do we need a slide for showing the path?] +.. #[punch: do we need a slide for showing the path?] We use the ``cat`` command to see the contents of this file. @@ -44,6 +49,10 @@ to do it] :: cat /home/fossee/primes.txt +.. #[Nishanth]: A problem for windows users. + Should we simply open the file and show them the data + so that we can be fine with GNU/Linux ;) and windows? + Now let us read this list into the variable ``primes``. :: @@ -71,6 +80,12 @@ This is how we look at the contents of the file, ``pendulum.txt`` cat /home/fossee/pendulum.txt +.. #[Nishanth]: The first column is L values and second is T values + from a simle pelculum experiment. + Since you are using the variable names later in the + script. + Not necessary but can be included also. + Let us, now, read the data into the variable ``pend``. Again, it is assumed that the file is in ``/home/fossee/`` :: @@ -90,12 +105,17 @@ two separate, simple sequences. L, T = loadtxt('/home/fossee/pendulum.txt', unpack=True) +.. #[Nishanth]: It has a sequence of items in which each item contains + two values. first is l and second is t + Let us now, print the variables L and T, to see what they contain. :: print L print T +.. #[Nishanth]: Stress on ``unpack=True`` ?? + Notice, that L and T now contain the first and second columns of data from the data file, ``pendulum.txt``, and they are both simple sequences. @@ -115,12 +135,14 @@ finished, resume the video to look at the solution. {{{ switch back to the terminal }}} :: - L, T = loadtxt('/home/fossee/pendulum.txt', unpack``True, delimiter``';') + L, T = loadtxt('/home/fossee/pendulum.txt', unpack=True, delimiter=';') print L print T +.. #[Nishanth]: L, T = loadtxt('/home/fossee/pendulum_semicolon.txt', ...) + This brings us to the end of this tutorial. {{{ show the summary slide }}} diff --git a/progress.org b/progress.org index 4142673..4d2574b 100644 --- a/progress.org +++ b/progress.org @@ -8,7 +8,7 @@ | 1.7 LO: | additional features of IPython | 2 | Nishanth | Amit (Pending) | Madhu (Pending) | | 1.8 LO: | module level assessment | 3 | Madhu | | | |---------+----------------------------------------+-------+----------+---------------------+---------------------| -| 2.2 LO: | loading data from files | 3 | Punch | | | +| 2.2 LO: | loading data from files | 3 | Punch | Nishanth (Done) | Anoop (Pending) | | 2.3 LO: | plotting the data | 3 | Amit | Anoop (Pending) | Punch (Pending) | | 2.4 LO: | other types of plots | 3 | Anoop | | | | 2.5 LO: | module level assessment | 3 | Nishanth | | | |