Log Values ​​for SFrame Column

Please can someone tell me how can I take the logarithm of each value in SFrame , graphlab (or DataFrame , pandas) without iterating over the entire length of the SFrame column? I am particularly interested in similar functions, for example, Groupby Aggregators for the log function. Could not find it ...

Important: Please, I am not interested in iterating for-loop for the entire length of the column. I'm only interested in a specific function that converts all values ​​to log values ​​for the entire column.

I am also very sorry if this feature is in the manual. Please just give me the link ...

+5
source share
3 answers

numpy provides an implementation for a large number of basic mathematical transformations. You can use them in all data structures that are built on numpy 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 based on numpy arrays.

+5
source

A similar pattern applies to SFrames. You can do:

 import graphlab import math sf = graphlab.SFrame({'a': [1, 2, 3]}) sf['b'] = sf['a'].apply(lambda x: math.log(x)) 
+3
source

@cel

I think in my case one could also use the following pattern.

 import numpy import pandas import graphlab df abc 1 1 1 1 2 3 2 1 3 .... df['log c'] = df.groupby('a')['c'].apply(lambda x: numpy.log(x)) 

for an SFrame object ( sf instead of df ) it may look a little different

 logvals = numpy.log(sf['c']) log_sf = graphlab.SFrame(logvals) sf = sf.join(log_sf, how = 'outer') 

The code snippet may be a bit long with numpy , but it works ...

The main problem is, of course, runtime. I really hoped I could use a specific function to minimize my time ....

-1
source

Source: https://habr.com/ru/post/1207201/


All Articles