lemeet
V2EX  ›  问与答

Python 怎么把上面的 df 变成下面的 df,麻烦大佬帮忙解答一下, Python 新手,谢谢

  •  
  •   lemeet · Nov 11, 2018 · 1367 views
    This topic created in 2742 days ago, the information mentioned may be changed or developed.

    user_id r_score f_score m_score
    0 1 5 1 1 1 2 2 1 1 2 5 4 1 1 3 7 2 1 1 4 9 2 1 1

    user_id r_score f_score m_score r_height r_height f_height m_height 0 1 5 1 1 高 低 低 1 2 2 1 1 高 低 低 2 5 4 1 1 高 低 低 3 7 2 1 1 低 低 低 4 9 2 1 1 低 低 低

    1 replies    2018-11-11 18:03:44 +08:00
    Yvette
        1
    Yvette  
       Nov 11, 2018 via iPad
    import pandas as pd
    pf = pd.DataFrame([[1, 2], [5, 3]])
    pf["height"] = pf.iloc[:, 0] > pd.iloc[:, 1]
    print(pf)
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2568 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 132ms · UTC 00:37 · PVG 08:37 · LAX 17:37 · JFK 20:37
    ♥ Do have faith in what you're doing.