Modifying particular elements in SFrame

User 739 | 9/23/2014, 8:47:09 AM

I have recently moved from R, & presently I have a SFrame (called ABC), with each column as integer datatype (at least the ones I want to modify). So when I do something like this for a column named "X1": <b class="Bold"><b class="Bold"><i class="Italic"><i class="Italic">ABC[1]['X1']=10</i></i></b></b>

The above statement runs without any errors, but when I do this <b class="Bold"><b class="Bold"><i class="Italic"><i class="Italic">ABC[1]['X1']</i></i></b></b> the value is still shown to be the previous value and not the modified value which I expect.

So, what am I doing wrong? Is there any way to do this type of modification?

(And this "<b class="Bold"><b class="Bold"><i class="Italic"><i class="Italic">ABC['X1']=10</i></i></b></b>" is working as expected!)


User 19 | 9/23/2014, 3:25:18 PM

Each SFrame column is immutable, which means the elements of that column cannot be changed. For a more in depth discussion of this, see the <a href="">User Guide</a> or <a href="">a description of the architecture</a>.

If you have a number of changes to make, then you may be interested in simply making a new column from the old 'X1' column via the apply function.

If you really need to modify a single element, here's an example of changing the second element in the 'old' column to be 100.

<pre>import graphlab sf = graphlab.SFrame({'old':[3,4,5]}) sf.addrownumber() sf['new'] = sf.apply(lambda x: 100 if x['id'] == 1 else x['old']) </pre>

You should end up with:

<pre>Columns: id int old int new int

Rows: 3

Data: +----+-----+-----+ | id | old | new | +----+-----+-----+ | 0 | 3 | 3 | | 1 | 4 | 100 | | 2 | 5 | 5 | +----+-----+-----+ [3 rows x 3 columns] </pre>