Search code examples
pandasdataframelogarithm

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...


Solution

  • 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.