0

I have a function func that takes two strings as input and returns an integer as an output. I have two different dataframes and I want to use the 'Name' column of both these dataframes as an input to the function.

Suppose,

In [12]: DF1
Out[12]: 
     Name
0   Apple
1  Banana
2  Orange

and

In [13]: DF2
Out[13]: 
     Name
0  Spider
1     Yak
2    Wolf

Now, I want use func and provide inputs to it like

func('apple','spider')
func('apple','yak')
func('apple','wolf')
func('banana','spider')
...

I tried doing this by using itertools but as the dataset is large it is taking a lot of time. So how could it be done using vectorized operations or what would be the most efficient way to do it?

edit: I am trying to do something like:

for i in DF1['Name']:
    for j in DF2['Name']:
        func(i,j)
Erick
  • 49
  • 6
  • Is this what you're doing? `for x, y in itertools.product(df1.Name, df2.name): f(x, y)` Why doesn't it work? – cs95 Jan 01 '18 at 13:03
  • @COLDSPEED It works, but as I stated the dataset is large, so using itertools is computationally expensive. I know that using vectorized operations in pandas are quite fast reference: [https://engineering.upside.com/a-beginners-guide-to-optimizing-pandas-code-for-speed-c09ef2c6a4d6] , but i could not figure out how to implement it in my problem. – Erick Jan 01 '18 at 13:08

0 Answers0