I see you've already imported numpy because you're using np.linspace in the code. You are probably confusing numpy's abs, which will happily work on lists and arrays, with __builtin__.abs, which only works for scalars.

Change this:

abs(wf[0:100])

To this:

np.abs(wf[0:100])
Answer from wim on Stack Overflow
🌐
Apache
spark.apache.org › docs › latest › api › python › _modules › pyspark › pandas › generic.html
Source code for pyspark.pandas.generic - Apache Spark
>>> df = ps.DataFrame({ ... 'a': [4, 5, 6, 7], ... 'b': [10, 20, 30, 40], ... 'c': [100, 50, -30, -50] ... }, ... columns=['a', 'b', 'c']) >>> df.abs() a b c 0 4 10 100 1 5 20 50 2 6 30 30 3 7 40 50 """ def abs(psser: "Series") -> Union["Series", Column]: if isinstance(psser.spark.data_type, BooleanType): return psser elif isinstance(psser.spark.data_type, NumericType): return psser._with_new_scol( F.abs(psser.spark.column), field=psser._internal.data_fields[0] ) else: raise TypeError( "bad operand type for abs(): {} ({})".format( spark_type_to_pandas_dtype(psser.spark.data_type), psser.spark.data_type.simpleString(), ) ) return self._apply_series_op(abs) # TODO: by argument only support the grouping name and as_index only for now.
🌐
Python Examples
pythonexamples.org › python-absolute-value-abs
abs() - Python Examples
Traceback (most recent call last): File "example1.py", line 2, in <module> absVal = abs(x) TypeError: bad operand type for abs(): 'str'
🌐
GitHub
github.com › HIPS › autograd › issues › 102
TypeError: bad operand type for abs(): 'FloatNode' · Issue #102 · HIPS/autograd
def predict(self, theta, data): const = assert_arr_shape({ data.X.shape: ('batch_size', self.n_steps, self.n_input_dim), data.y.shape: ('batch_size', self.n_hidden_dim) }) h_prev = bk.repeat(theta.h_0[:, bk.newaxis], const.batch_size, axis=1).T activation = lambda x: bk.maximum(0, 1-x) to_stack = [] for i in range(self.n_steps): input2hidden = bk.dot(data.X[:, i, :], theta.W_input_to_hidden) hidden2hidden = bk.dot(h_prev, theta.W_hidden_to_hidden) before_activation = (input2hidden + hidden2hidden) h_prev = activation(before_activation) to_stack.append(h_prev) output = bk.stack(to_stack, axis=1) assert_arr_shape({output.shape: (None, self.n_steps, self.n_hidden_dim)}) return output def loss(self, theta, data): pred = self.predict(theta, data) last_step_pred = pred[:, -1, :] loss = bk.sum(bk.abs(last_step_pred - data.y)) return loss
🌐
GitHub
github.com › CenterForMedicalGeneticsGhent › WisecondorX › issues › 79
TypeError: bad operand type for abs(): 'str' · Issue #79 · CenterForMedicalGeneticsGhent/WisecondorX
August 14, 2020 - Traceback (most recent call last): File "/home/tgd/.local/bin/WisecondorX", line 8, in sys.exit(main()) File "/home/tgd/.local/lib/python3.8/site-packages/wisecondorX/main.py", line 404, in main args.func(args) File "/home/tgd/.local/lib/python3.8/site-packages/wisecondorX/main.py", line 244, in tool_test generate_output_tables(rem_input, results) File "/home/tgd/.local/lib/python3.8/site-packages/wisecondorX/predict_output.py", line 43, in generate_output_tables _generate_chr_statistics_file(rem_input, results) File "/home/tgd/.local/lib/python3.8/site-packages/wisecondorX/predict_output.py",
Published   Apr 29, 2021
🌐
Seaborn Line Plots
marsja.se › home › programming › python › how to get absolute value in python with abs() and pandas
How to get Absolute Value in Python with abs() and Pandas
May 26, 2024 - Now, x can be any number we want to find the absolute value. For instance, if x is positive or negative zero, Pythons abs() function will return a positive zero. If we, however, put in something that is not a number, we will get a TypeError (“bad operand type for abs(): ‘str’”.
🌐
Sparkreference
sparkreference.com › reference › abs
Introduction to the abs() function in PySpark - Spark Reference
If you encounter a TypeError stating "unsupported operand type(s) for abs()", make sure you are applying abs() on a compatible data type. Handle null values using the coalesce() function or other suitable techniques. Consider performance implications and optimize your code accordingly.
Top answer
1 of 1
1

I don't recommend you use apply here

Use GroupBy.idxmax + DataFrame.replace

max_df = df.abs().groupby(np.arange(len(df)) // n).idxmax().replace(df)
print(max_df)

Output

           A          B          C          D
0  95.483784  72.261024  90.289008 -99.557204
1  92.303663 -92.933734  98.741863 -73.221129
2 -94.858459  91.925163  90.394739  94.129047
3  85.727608  96.168424  69.747412  74.943672

print(df)
 # df = pd.read_clipboard() # read

            A          B          C          D
0  -49.710250 -44.714960  90.289008  78.021054
1   15.779849  72.261024 -80.564941 -99.557204
2  -25.535893  44.418568  -3.654055  -4.656012
3   -1.792691  52.828214 -24.383645  54.337480
4   95.483784 -33.604944  60.210426 -68.157859
5   85.614669 -88.756766  14.634241 -73.221129
6   -1.461207  41.078068  98.741863   0.152652
7   92.303663 -77.230608  63.205845 -45.439176
8   36.255957 -92.933734  -8.668916  24.251590
9   15.387012 -17.044411 -84.098159  53.797730
10 -15.277586  91.925163  90.394739  94.129047
11 -94.858459  19.069534  62.672051  10.852176
12 -48.550836  59.084142 -22.185758 -58.797477
13 -16.430060 -26.718411 -23.169127  90.198812
14  14.495206  14.054623 -59.593696  35.043442
15  21.148221  16.673029  42.788121 -23.932640
16  74.617433 -53.114081  69.747412  74.943672
17  85.727608  96.168424  41.474511   7.672894
18  -9.282754  -0.151546  -8.765613 -26.973899
19 -39.272002  85.819052  21.355006  67.018427

The problem is that Groupby.apply apply the function to each daframe, then max receives a dataframearg... We could check it with:

def absmax(x):
    print('This is a DataFrame arg: \n', x)
    return x.apply(lambda y: max(y, key=abs))

df_max = df.groupby(np.arange(len(df))//n).apply(absmax)

This is a DataFrame arg: 
            A          B          C          D
0  23.080753  89.918599 -62.273324   0.674636
1 -61.096176  68.840583  20.359616 -82.110220
2 -86.942716  97.269852  57.320944  84.340152
3  36.632979  53.376849  95.817563  39.398515
4 -36.960907 -12.796490 -79.833804  32.708664
This is a DataFrame arg: 
            A          B          C          D
5  24.360600 -49.486819 -65.995965 -93.884078
6 -46.623600 -57.999896 -86.946372  -0.250644
7 -35.103092  61.971385  86.165203 -32.619381
8  50.155064 -38.999355  98.856747 -56.195841
9 -92.646512  94.217864 -86.628196 -55.859978
This is a DataFrame arg: 
             A          B          C          D
10 -55.846413  34.281246 -90.523268  71.148029
11  22.753896 -33.659637  74.225409  24.498337
12 -52.384172  16.169118 -10.788839 -99.874961
13  49.235215 -74.372901  11.509361 -43.676953
14  67.255287 -84.477123  12.725054 -85.892184
This is a DataFrame arg: 
             A          B          C          D
15  72.522972 -13.079824  48.973703 -87.913843
16 -64.110924 -81.324560   7.067080  97.073997
17  87.319482  76.021534  80.780322 -90.320084
18 -84.848110  70.732111  34.160013  99.269365
19 -17.924337  12.191496  46.020178  30.532568
🌐
TutorialKart
tutorialkart.com › python › pandas › pandas-dataframe-abs
Absolute Function to each Element of DataFrame in Pandas
July 12, 2021 - Example.py · </> Copy · import ... print(result) Output · TypeError: bad operand type for abs(): 'str' Absolute method works only with numeric elements....
Find elsewhere
🌐
GitHub
github.com › facebook › pyre-check › issues › 798
PySpark - Incompatible parameter type & Unsupported operand · Issue #798 · facebook/pyre-check
April 8, 2023 - $ pyre check ƛ Found 16 type errors! sample.py:9:23 Unsupported operand [58]: `+` is not supported for operand types `pyspark.sql.column.Column` and `int`. sample.py:9:23 Incompatible parameter type [6]: In call `pyspark.sql.dataframe.DataFrame.withColumn`, for 2nd positional argument, expected `Column` but got `int`. sample.py:10:23 Unsupported operand [58]: `-` is not supported for operand types `pyspark.sql.column.Column` and `int`. sample.py:10:23 Incompatible parameter type [6]: In call `pyspark.sql.dataframe.DataFrame.withColumn`, for 2nd positional argument, expected `Column` but got `
Author   tomas-pihrt
🌐
Real Python
realpython.com › python-absolute-value
How to Find an Absolute Value in Python – Real Python
June 4, 2025 - >>> temperature_readings = [1, -5, 1, -4, -1, -8, 0, -7, 3, -5, 2] >>> abs(temperature_readings) Traceback (most recent call last): File "<stdin>", line 1, in <module> TypeError: bad operand type for abs(): 'list'
🌐
Scaler
scaler.com › home › topics › python abs() function
Python abs() Function - Scaler topics
December 4, 2023 - As we can see, we passed the 'str' data type to abs() function, and the result is an error - bad operand type.
🌐
Apache
spark.apache.org › docs › latest › api › python › reference › pyspark.sql › api › pyspark.sql.functions.abs.html
pyspark.sql.functions.abs — PySpark 4.1.1 documentation
Example 2: Compute the absolute value of a double column · >>> from pyspark.sql import functions as sf >>> df = spark.createDataFrame([(-1.5,), (-2.5,), (None,), (float("nan"),)], ["value"]) >>> df.select("*", sf.abs(df.value)).show() +-----+----------+ |value|abs(value)| +-----+----------+ | -1.5| 1.5| | -2.5| 2.5| | NULL| NULL| | NaN| NaN| +-----+----------+
🌐
iO Flood
ioflood.com › blog › python-absolute-value
Python Absolute Value | abs() Function and Alternatives
February 6, 2024 - string = 'I am not a number' try: absolute_value = abs(string) except TypeError: print('TypeError: bad operand type for abs(): str') # Output: # TypeError: bad operand type for abs(): str
🌐
Checkio
py.checkio.org › forum › post › 13102 › bad-operand-type-for-abs-how-do-i-solve-this
'Bad operand type for abs', how do i solve this
def checkio(numbersarray: tuple) -> list: result = sorted([numbersarray], key=lambda x:abs(x)) return result
🌐
Stack Overflow
stackoverflow.com › questions › 73438188 › how-to-correctly-apply-python-absolute-value-to-a-list-to-avoid-an-typeerror-ba
cryptography - How to correctly apply Python absolute value to a list to avoid an TypeError: bad operand type for abs(): 'list' - Stack Overflow
in B i need to use list, but I can't find a workaround for TypeError: bad operand type for abs(): 'list'. Following the documentation of ABS I tried to use map() and list() function to convert it to the absolute value,
🌐
Studytonight
studytonight.com › pandas › pandas-dataframe-abs-method
Pandas DataFrame abs() Method - Studytonight
-----DataFrame----- A B C 0 abc xyz pqr 1 2 -1.259 -85 Traceback (most recent call last): File "<string>", line 8, in <module> File "/usr/local/lib/python3.8/dist-packages/pandas/core/generic.py", line 1381, in __abs__ return self.abs() File "/usr/local/lib/python3.8/dist-packages/pandas/core/generic.py", line 9723, in abs return np.abs(self) TypeError: bad operand type for abs(): 'str' In the below example we will get the absolute value series elements with complex numbers. The abs() the method returns only the magnitude part of the number. For complex inputs, the absolute value is ?a2+b2 · #importing pandas as pd import pandas as pd df = pd.DataFrame([[1.2 + 1j,-22,-12],[2, -1.259, -85]],columns=['A', 'B','C']) print("-----DataFrame-----") print(df) print(abs(df)) Once we run the program we will get the following output.