I have a pandas series, s1, and I want to make a new series, s2, by applying a function that takes two inputs to create one new value. This function would be applied to a 2-value window on s1. The resulting series, s2, should have one fewer value than s1. There are many ways to accomplish this but I'm looking for a way to do it very efficiently. This is on Linux and I'm currently running python 2.7 and 3.4 and pandas 15.2, though I can update pandas if that's necessary. Here's a simplification of my problem. My series consists of musical pitches represented as strings.
import pandas
s1 = pandas.Series(['C4', 'E-4', 'G4', 'A-4')
I'd like to use this function:
def interval_func(event1, event2):
ev1 = music21.note.Note(event1)
ev2 = music21.note.Note(event2)
intrvl = music21.interval.Interval(ev1, ev2)
return intrvl.name
On s1 and a shifted version of s1, to get the following series:
s2 = pandas.Series(['m3', 'M3', 'm2'])