如何定义多个列值并使用.map函数调用?

2024-07-05 09:12:23 发布

您现在位置:Python中文网/ 问答频道 /正文

Using the code below I need to place the values ("Right Data, Incorrect Data...) into a column "Assessment" when the if condition satisfies based on x and y values. But I am getting the below error

AttributeError:'DataFrame'对象没有属性“map”

def variable(x,y):
    x = df['Volume']
    y = df['Turnover']
    if df[(x==0) & (y==0)]:
        return 'Right Data'
    if df[(x>0) & (y>0)]:
        return 'Right Data'
    if df[(x<0) & (y<0)]:
        return 'Right Data'
    if df[(x>0) & (y<0)]:
        return 'Incorrect Data'
    if df[(x<0) & (y>0)]:
        return 'Incorrect Data'
    if df[(x!=0) & (y==0)]:
        return 'Incorrect Data'
    if df[(x==0) & (y!=0)]:
        return 'Incorrect Data'
    if df[(x==0) & (y.isnull())]:
        return 'Missing Data'
    if df[(x=='Nan') & (y!=0)]:
        return 'Missing Data'
test = df[['Volume','Turnover']]
test2 = test.map(variable)
df['Assessment'] = test2

Tags: therightmapdfdatareturnifvariable