Pandas 如果一列存在,另一列为NaN/Null,则将值从一列复制到另一列

Pandas 如果一列存在,另一列为NaN/Null,则将值从一列复制到另一列,pandas,Pandas,以上是我的数据帧,我希望使用performance\l和performance\r。 如果performance\u l和performance\r中的一个为空。。。 将存在的值复制到其他列,否则忽略所有数据帧 预期产出: import pandas as pd import io output = """ name weight performance_l performance_r Arash 62.2

以上是我的数据帧,我希望使用
performance\l
performance\r
。 如果
performance\u l
performance\r
中的一个为空。。。 将存在的值复制到其他列,否则忽略所有数据帧

预期产出:

import pandas as pd
import io

output = """
name    weight   performance_l    performance_r
Arash   62.2                   100       
Bash    91.2       90           79       
Kim     88.2       85           85      
Dim     92.1       90           95
Ghst    63.2       60           65      
"""

df = pd.read_table(io.StringIO(output), delim_whitespace=True)

无论如何要实现这一点?

使用
fillna

output = """
name    weight   performance_l    performance_r
Arash   62.2       100          100       
Bash    91.2       90           79       
Kim     88.2       85           85      
Dim     92.1       90           95
Ghst    63.2       60           65      
"""

df = pd.read_table(io.StringIO(output), delim_whitespace=True)
df['performance_l'] = df['performance_l'].fillna(df['performance_r'])
df['performance_r'] = df['performance_r'].fillna(df['performance_l'])