Have some way to apply a function in a pandas.Series using different values of another pandas.Series? I know that have the pandas.Series.apply(), but I need something like that:
array1 = pandas.Series([1, 2, 3, 4])
array2 = pandas.Series([5, 5, 6, 0])
def func(x, y):
return x+y
print(array1.apply(func, args = array2))
Out:
0 6
1 7
2 9
3 4
In other words, I need apply a function in a pandas.DataFrame column by I need use another column of same pandas.DataFrame. Using the same function func:
df = pandas.DataFrame({'a': [1, 2, 3, 4], 'b': [5, 5, 6, 0]})
df['c'] = df['a'].apply(func, args = df['b'])
print(df)
Out:
a b c
0 1 5 6
1 2 5 7
2 3 6 9
3 4 0 4
Thank you!
I need use the apply because I use multiprocessing like pandarallel, so I just change apply() for parallel_apply(), someone know a way to do it? Use multiprocessing with operations that use two columns?