[英]Pandas dataframe. Wrong series fly in the line
Use fillna
.使用fillna
。 Basically, use the values in the second column to fill holes in the first column:基本上,使用第二列中的值来填充第一列中的孔:
df['first_column'].fillna(df['second_column'])
For example, if you have DataFrame df
:例如,如果您有 DataFrame df
:
a b
0 1.0 NaN
1 2.0 NaN
2 NaN 100.0
then然后
df['a'] = df['a'].fillna(df['b'])
df = df.drop(columns=['b'])
Output: Output:
a
0 1.0
1 2.0
2 100.0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.