assign new values to a column of H2o dataframe in python

474 views
Skip to first unread message

Paul Xiao

unread,
May 19, 2016, 7:46:46 PM5/19/16
to H2O Open Source Scalable Machine Learning - h2ostream
One column of a H2oFrame contains integers 0-10, I'd like to assign 0 to those <=5, and 1 to those > 5. What is the fastest way to do it. Using a loop takes a long time.

Lauren DiPerna

unread,
May 19, 2016, 8:50:22 PM5/19/16
to Paul Xiao, H2O Open Source Scalable Machine Learning - h2ostream
Which language are you working in?

On Thu, May 19, 2016 at 4:46 PM, Paul Xiao <yx7...@gmail.com> wrote:
One column of a H2oFrame contains integers 0-10, I'd like to assign 0 to those <=5, and 1 to those > 5. What is the fastest way to do it. Using a loop takes a long time.

--
You received this message because you are subscribed to the Google Groups "H2O Open Source Scalable Machine Learning - h2ostream" group.
To unsubscribe from this group and stop receiving emails from it, send an email to h2ostream+...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Lauren DiPerna

unread,
May 20, 2016, 4:27:20 PM5/20/16
to Paul Xiao, H2O Open Source Scalable Machine Learning - h2ostream
Sure, for Python or R you can use ifelse()

Here's the example in Python:

test_h2o = h2o.H2OFrame({'col_1':range(11), 'col_2':range(11,22)})
test_h2o['col_1'] = h2o.H2OFrame.ifelse(test_h2o['col_1'] <=5,0,1)
test_h2o



Lauren DiPerna

unread,
May 20, 2016, 5:19:15 PM5/20/16
to Paul Xiao, H2O Open Source Scalable Machine Learning - h2ostream
or you can do

test_h2o['col_1'] = (test_h2o['col_1'] <=5).ifelse(1,0)
Reply all
Reply to author
Forward
0 new messages