Join GitHub today
DataFrame.apply() raises ValueError when output df is different size than input df #17437
import numpy as np import pandas as pd df = pd.DataFrame(np.random.rand(10, 2)) # dummy array df1 = df.apply(np.fft.fft, axis=0) # works print(df1.shape) # for testing df2 = df.apply(np.fft.rfft, axis=0) # breaks print(df2.shape) # for testing
I would like to take a DataFrame of time series and apply the real-fft along the columns, but it seems that DataFrame.apply only works if the function to be applied returns output that is the same size as the input.
I expect the code block above to run without error and produce the following output:
(10, 2) (6, 2)
Alternatively, raising an error that tells the user "output array size must match input array size" would be fine, if we want to restrict apply to working only for functions that return the same-size arrays as the inputs.
Yeah, I figured that this was non-trivial. I suppose the easiest fix would be to just update the documentation so that it explicitly states that