Advertisement
Guest User

Untitled

a guest
May 27th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.57 KB | None | 0 0
  1. ### 1 np.where
  2.  
  3. lcoe['MEWC'] =\
  4. np.where((lcoe['country']=='NG') &\
  5.          (lcoe['sector'].isin([17, 18, 19, 20])),\
  6.          lcoe['MEWC'] / 10 ** 3, lcoe['MEWC'])
  7.  
  8. ### 2 define select
  9.  
  10. select = (lcoe['country']=='NG') &\
  11.          (lcoe['sector'].isin([17, 18, 19, 20]))
  12.  
  13. lcoe.loc[select, 'MEWC'] =\
  14. lcoe[select].apply(lambda x: x['MEWC'] / 10 ** 3)
  15.  
  16. ### 3 copy, modify, update
  17.  
  18. temp = lcoe[(lcoe['country']=='NG') &\
  19.          (lcoe['sector'].isin([17, 18, 19, 20]))].copy()
  20.  
  21. temp = temp.assign(MEWC = lambda x: x['MEWC'] / 10 ** 3)
  22. lcoe = lcoe.update(temp)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement