-
-
Notifications
You must be signed in to change notification settings - Fork 11.7k
Description
Describe the issue:
From the attached CSV file, input_data.csv, I import the, say, test_list. Then, I create a pd.Dataframe to store my data in test_df.
import numpy as np
test_df = pd.DataFrame(index=range(len(test_list)), columns=['test'])
test_df['test'] = test_list
I want to calculate the FFT transform of the signal in test_df['test']. However, I get different results when I pass as input different types of arguments to the np.fft.fft().
Once I pass the signal as a nympy.array I get the plot#1.
Once I pass the signal as a pd.Dataframe I get the plot#2.
Both inputs, np.array and pd.DataFrame contain the same information.
From the problem definition the plot#2 seems to have a better physical interpretation.
However, it is not clear why I get different results.
May be it is a bug?
The code I use is below:
import numpy as np
test_df = pd.DataFrame(index=range(len(test_list)), columns=['test'])
test_df['test'] = test_list
########## PLOT 1: from Numpy ##############
to_np = test_df['test'].to_numpy()
print(to_np)
fft_output = np.fft.fft(to_np)
power = np.abs(fft_output)
freq = np.fft.fftfreq(len(to_np))
mask = freq >= 0
freq = freq[mask]
power = power[mask]
plt.plot(freq, power)
plt.show()
########## PLOT 2: from pd.DataFrame ##############
to_df = test_df['test'].to_frame()
print(to_df)
fft_output = np.fft.fft(to_df)
power = np.abs(fft_output)
freq = np.fft.fftfreq(len(to_df))
mask = freq >= 0
freq = freq[mask]
power = power[mask]
plt.plot(freq, power)
plt.show()
Reproduce the code example:
import numpy as np
test_df = pd.DataFrame(index=range(len(test_list)), columns=['test'])
test_df['test'] = test_list
########## PLOT 1: from Numpy ##############
to_np = test_df['test'].to_numpy()
print(to_np)
fft_output = np.fft.fft(to_np)
power = np.abs(fft_output)
freq = np.fft.fftfreq(len(to_np))
mask = freq >= 0
freq = freq[mask]
power = power[mask]
plt.plot(freq, power)
plt.show()
########## PLOT 2: from pd.DataFrame ##############
to_df = test_df['test'].to_frame()
print(to_df)
fft_output = np.fft.fft(to_df)
power = np.abs(fft_output)
freq = np.fft.fftfreq(len(to_df))
mask = freq >= 0
freq = freq[mask]
power = power[mask]
plt.plot(freq, power)
plt.show()Error message:
No response
Runtime information:
1.23.5
3.9.16 | packaged by conda-forge | (main, Feb 1 2023, 21:38:11)
[Clang 14.0.6 ]
Context for the issue:
No response

