SHARE
TWEET

[PYSTOCK] DataFrame Column 선택 추가

mmyjh86 Aug 25th, 2019 98 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from pandas import DataFrame
  2.  
  3. data = [[100,   0],
  4.         [200,   0],
  5.         [  0,  50],
  6.         [  0, 300]]
  7.  
  8. df = DataFrame(data, columns=["col1", "col2"])
  9. 조건 = df["col1"] == 0
  10.  
  11. df["col3"] = 0
  12. df.loc[ 조건, "col3"] = df["col2"]
  13. df.loc[~조건, "col3"] = df["col1"]
  14. print(df)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top