Debugging Series – logbook

General: How to debug?

  1. A post in general , covers how to use pdb and debugging strategies in general
    1. insert breakppint by pdb.set_trace
  2. Execute file from within Python interpreter 

Another bug with apply function!

So I am trying to apply a DataFrame function to Panel object.
def getAsset0(df):
df.Share = np.floor(df.Cash[0]/df.Close[0])
df.Cash = df.Total[0] - df.Share[0] * df.Close[0]
df.Position = df.Share * df.Close
df.Total = df.Cash + df.Position
return (df);

s0pnl = pnl.apply(lambda x:getAsset0(x), axis=(1, 2))

Mistakes I made:

  1. I used df[‘Share’] to do indexing. This returns a copy rather than a view. Thus, when doing changes will not modify original dataset.
  2. I used pnl.apply(lambda x:getAsset0(x), axis=(1, 2)) to do batch operation. But some problem with lambda function?


Jun 26

  • Today’s bug: in Pandas dataframe there is a blank after the column name. Thus, when retrieving the blank is left out…. and thus cannot cite the column.
Share this post

Leave a Reply

Your email address will not be published. Required fields are marked *