本文介绍了从以前的列填充空白单元格 pandas 的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
查看列并找到空白值。 查看进入上一个_mark列,并且仅为空白单元格带来价值。
如果我有一个简单的数据框架,例如:
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:
我可以做强力复制和粘贴样式格式,但是这会丢失任何与前一列不同的单元格,即 - > 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
发布评论