I have a pandas df where one column lists a particular func used to get the result in that line of the df.
It appears that Python changes the name of a func. if it is part of a list of functions. So Python takes the func name 'strategy0' and changes it to the less useful '<function strategy0 at 0x0000000009CCA488>'
if it is part of a list of functions.
How can I either avoid Python changing the fct name alltogether or use Reg. Ex. to create a new df column 'stratname' with the proper fct. name (changing it back)?
This is my df as it looks now:
Strategy Ticker ROI
0 <function strategy0 at 0x0000000009CCA488> nflx 142.976946
1 <function strategy0 at 0x0000000009CCA488> lnkd 61.710992
2 <function strategy0 at 0x0000000009CCA488> hsp 8.589611
This is how I would like it to look:
Strategy Ticker ROI
0 strategy0 nflx 142.976946
1 strategy0 lnkd 61.710992
2 strategy0 hsp 8.589611
This way the column info could be used directly as input for a new function.
A good friend of mine helped me to the below code. But he is not profficient in pandas, so we're kind of struggling with it.
def format(x):
m = re.search(r'<function\s+(strategy\d+)\s+.*, x)
return m.groups(1)
df_max_res['stratname'] = df_max_res['Strategy'].applymap(format)
This seems to look a lot like my problem, but apparantly Python3 handles this differently than P2. Return function name in python?