numpy - Python- New Variable inidcator -


so want make new indicator variable dataframe (df), want read "splits" unless field (assetclass) "future" in case want new indicator read "notsplit" code im using @ moment is:

df['category'] = 'split' df[df.assetclass == "future"].category = 'notsplit'  

but far seems make new variable , call "split" , skip on next line. can see problems here?

like this?

df['category'] = 'notsplit' if df.assetclass == 'future' else 'split' 

some background: new key in dict (either true or false) because result of df.assetclass == 'future' evaluation used. on other words, following:

df['category'] = 'split' df[true] = 'notsplit' 

if want update entry, reuse same key name.

the above solution in multiple lines comes down following:

df['category'] = 'split' if df.assetclass == 'future':     df['category'] = 'notsplit' 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -