'Why does using .abs() and np.abs() return different values for a pandas dataframe?

i've got code that looks like this:

# Fourier Transfrom LETSGOOOOO whooooo
df_ = df['Open']
fft = tf.signal.fft(np.asarray(df_.tolist()))
fft_df = pd.DataFrame({'fft':fft})
fft_df['absolute'] = fft_df['fft'].apply(lambda x: np.abs(x))
fft_df['abs'] = fft_df['fft'].abs()

fft_df.head()

I found the code using the lambda function in a tutorial and wondered why the person chose to use that instead of simply using .abs() and so I added a column where I used .abs() to check if there's any difference and here's how the fft_df dataframe looks:

fft                         absolute       abs
36676.699219+127348.875000j 132525.153195 132525.156250
15539.641602+142518.187500j 143362.876050 143362.875000
61908.781250+18788.427734j  64697.003119  64697.003906
15287.801758+26563.015625j  30648.175830  30648.175781

abs is the .abs() values and absolute is the lambda method values

there appears to be a slight difference in the value, where the value before the decimal is the the same but after the decimal it seems to change by a lot. why is this?

also the df that ive used in the line: df['Open'] can be obtained using the following code, the label names are the same so that won't be a problem, also you'll have to install a module for this.

!pip install yfinance
import yfinance as yf

df = yf.download('GS', period='max', progress=False)

the df['Open'] column is of the type float if that helps.

ps: apologies for any formatting mistakes



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source