Assigning values in SFrame

User 2610 | 11/19/2015, 8:05:50 PM

How to assign a particular value to a particular raw or number of ras in an Frame? For example I want to replace all 'a's with 'd's as follows: train[train['ColName']=='a']['ColName'] = 'd' This does not work this way? any help please?


User 19 | 11/19/2015, 9:07:11 PM


Each column of an SFrame is immutable: it cannot be changed once it's created. You can create a new column (i.e. SArray) that has all of these values replaced via:

train['new_col'] = train['ColName'].apply(lambda x: 'd' if x == 'a' else x)

You could also overwrite the original column by replacing 'new_col' with 'ColName' in the above code.

Thanks! Chris