Creating a new columns into data frame from calculation over data

Sometime you may need to operate either the full data frame or a specific column with a function and add new column which consist the results. This is how you can do it:

# Create a test frame
c_names = ['Prediction']
data1 = np.array([[0.12],
                  [0.43],
                  [0.90],
                  [0.002],
                  [0.52]])
df = h2o.H2OFrame().from_python(data1, destination_frame='df', column_names=c_names)

# Applying the function on specific column from frame and creating new column into same data frame:
df['new_prediction'] = df['Prediction']*1000
print df
Thats it, enjoy!!
Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s