Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log values by SFrame column

Please, can anybody tell me, how I can take logarithm from every value in SFrame, graphlab (or DataFrame, pandas) column, without to iterate through the whole length of the SFrame column? I specially interest on similar functionality, like by Groupby Aggregators for the log-function. Couldn't find it someself...

Important: Please, I don't interest for the for-loop iteration for the whole length of the column. I only interest for specific function, which transform all values to the log-values for the whole column.

I'm also very sorry, if this function is in the manual. Please, just give me a link...

like image 888
Guforu Avatar asked Nov 19 '14 09:11

Guforu


2 Answers

numpy provides implementations for a wide number of basic mathematical transformations. You can use those on all data structures that build on numpy's ndarray.

import pandas as pd
import numpy as np
data = pd.Series([np.exp(1), np.exp(2), np.exp(3)])
np.log(data)

Outputs:

0    1
1    2
2    3
dtype: float64

This example is for pandas data types, but it works for all data structures that are based on numpy arrays.

like image 199
cel Avatar answered Nov 18 '22 18:11

cel


The same "apply" pattern works for SFrames as well. You could do:

import graphlab
import math

sf = graphlab.SFrame({'a': [1, 2, 3]})
sf['b'] = sf['a'].apply(lambda x: math.log(x))
like image 5
papayawarrior Avatar answered Nov 18 '22 17:11

papayawarrior