Hi all,
Screen Link:
https://app.dataquest.io/m/346/working-with-strings-in-pandas/2/using-apply-to-transform-strings
I used the apply method with a function to select the word at -1 position on the CurrencyUnit and problem and timed it and got back 991 microseconds while the series str method (https://app.dataquest.io/m/346/working-with-strings-in-pandas/3/vectorized-string-methods-overview) gave me 1.73 milliseconds even though series.str was told to be faster than the apply.
Anybody has any insight on this?
My Code:
#Apply method:
def extract(element):
raw=str(element)
splitd=raw.split()
word=splitd[-1]
return word
%time merged["CurrencyUnit"]=merged["CurrencyUnit"].apply(extract)
merged["CurrencyUnit"].head()
#Series.str method:
%time merged['CurrencyUnit']=merged['CurrencyUnit'].str.split().str.get(-1)
merged['CurrencyUnit'].head()
What I expected to happen:
I expected series.str to be faster
What actually happened:
Apply method turned out to be faster
 