从以前的列填充空白单元格 pandas

编程入门 行业动态 更新时间:2024-10-21 20:40:47
本文介绍了从以前的列填充空白单元格 pandas 的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

如果我有一个简单的数据框架,例如:

If I have a simple dataframe such as:

q_1 q_1_mark q_2 q_2_mark TRUE a 1 c FALSE b 2 TRUE c 3

如何填写空白值q_2_mark列,所以他们与q_1_mark匹配?所以步骤是:

How could I fill in the blank values of the q_2_mark column, so they matched with q_1_mark? So the steps would be:

  • 查看列并找到空白值。
  • 查看进入上一个_mark列,并且仅为空白单元格带来价值。
  • 我可以做强力复制和粘贴样式格式,但是这会丢失任何与前一列不同的单元格,即 - > c

    I can do brute force copy and paste style formatting, but this loses any cells that contain anything different from the previous column, i.e a --> c

    推荐答案

    假设您的数据框为 df ,尝试:

    Assuming your dataframe is df, Try:

    df.q_2_mark = df.q_2_markbine_first(df.q_1_mark) q_1 q_1_mark q_2 q_2_mark 0 True a 1 c 1 False b 2 b 2 True c 3 c

    更多推荐

    从以前的列填充空白单元格 pandas

    本文发布于:2023-10-28 19:26:19,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1537564.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:单元格   空白   pandas

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!