Advertisement
mmyjh86

[PYSTOCK] DataFrame Column 선택 추가

Aug 25th, 2019
234
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.28 KB | None | 0 0
  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)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement