下面是我的数据框。在这里,我试图使用多个if条件不填充列中的任何值。但是我尝试的代码无法正常工作。
将熊猫作为pd导入
# intialise data of lists.
data = { 'Region': ['APAC', 'EMEA', 'EMEA', 'APAC']
, 'Country': ['Germany', 'None', 'UK', 'India']
, 'Site': ['None', 'None', 'None', 'Goldhill']
}
# Create DataFrame
df4 = pd.DataFrame(data)
# Print the output.
df4
我尝试了以下方法:但收到错误消息:
if ( df['Region'] != None
and df['Country'] == None
and df['Site'] == None
):
f['Country','Site'] = 'Region_Access'
elif ( df['Region'] != None
and df['Country'] != None
and df['Site'] == None
):
df['Site'] = 'Country_Access'
else :
df['Country','Site'] = 'No_Data'
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
预期输出:
data = { 'Region': ['APAC', 'EMEA', 'EMEA', 'APAC']
, 'Country': ['Germany', 'Region_Access', 'UK', 'India']
, 'Site': ['Country_Access', 'Region_Access', 'Country_Access', 'Goldhill']
}
# Create DataFrame
output = pd.DataFrame(data)
output