I'm a newbie to pandas dataframe, and I wanted to apply a function taking couple of rows in the same column. Like when you apply the function diff(), but i want to calculate the distance between text. so i defined a function which measure the distance, and i tried to use apply but i don't know how can i pick couple of rows. Below i show an example that i'have tried to do and what i expected:
def my_measure_function(x,y):
return some_distance_calculus(x,y)
>>> from pandas import DataFrame
>>> df = DataFrame({"text": ['hello','hella','hel'], "B": [3,4,4]})
>>> df['dist'] = df.apply(lambda x, y: my_measure_function(x, y), axis=0)
but it doesn't work. What i want to obtain is:
>>> df
text B dist
0 hello 3 0
1 hella 4 1
2 hel 4 2
Thanks in advance for any help that you can provide me.