[英]Fill Blank Row in a specific column with value from another column using pandas
If I have the following pandas dataframe如果我有以下熊猫数据框
A B
0 Cat Dog
1 Mouse Mouse
2 Fish "Blank"
How do I parse through column B, identify that there is a blank value and then if there is a blank value fill in the blank with "Fish", so the desired data frame is:我如何通过B列解析,确定有一个空白值,然后如果有一个空白值用“鱼”填充空白,所以所需的数据框是:
A B
0 Cat Dog
1 Mouse Mouse
2 Fish Fish
You could try this -你可以试试这个——
import numpy as np
df['B'] = np.where(df['B'] == 'Blank', df['A'], df['B'])
df[df['B'] == 'Blank'] = 'Fish'
df[df=='Blank'] = 'Fish'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.