I'd like to write custom functions that I can call on my pd.DataFrame df using the df.method() notation.
For instance,
def my_pd_method(df: pd.DataFrame, col: str)->pd.DataFrame:
'''apply my_function to df[col] of df'''
df_copy = df.copy(deep = True)
df_copy[col] = df_copy[col].apply(lambda x: my_function(x), axis = 1)
return df_copy
After this, I can run the command
PandasObject.my_pd_method = my_pd_method
to define the my_pd_method as a pd method.
After this, df.my_pd_method(col) will run as expected.
Is there some way to do this in a single function that I can put it in a library, import it and start using it, without having to run PandasObject.my_pd_method = my_pd_method?