python - Reshaping a column based on another column in a pandas dataframe -


date          sin      ret 01/01/1990    true    0.03   01/02/1990    true    0.02 01/01/1990    false   0.01   01/02/1990    false   0.05   

i

date          ret1    ret2 01/01/1990    0.03    0.01 01/02/1990    0.02    0.05 

so can

date          ret1-ret2 01/01/1990    0.02 01/02/1990    -0.03 

what best way this? thinking setting date , sin index , unstack sin. there easier way?

i think setting index , stacking idea here alternative pivot:

(df.pivot(index='date', columns='sin', values='ret')    .rename(columns={true: 'ret1', false: 'ret2'}))  sin         ret1  ret2 date                   01/01/1990  0.03  0.01 01/02/1990  0.02  0.05 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -