I'm relatively new to python and pandas. I came across the following issue/problem.
Below, when I use the test_fnc on the series it works, but when I apply it on the series via the series.apply(test_fnc) method, I get "TypeError: 'int' object is not iterable" error.
Code:
import pandas as pd
series = pd.Series([1,2,4,777,5])
print(series)
test_fnc = lambda u: [-x if x==777 else x for x in u]
print(test_fnc(series))
series.apply(test_fnc)
Output:
0 1
1 2
2 4
3 777
4 5
dtype: int64
[1, 2, 4, -777, 5]
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-14-77e41380f6db> in <module>
4 test_fnc = lambda u: [-x if x==777 else x for x in u]
5 print(test_fnc(series))
----> 6 series.apply(test_fnc)