在中使用if条件时获取此错误python.使用a、 空、a.bool()、a.item()、a.any()或a.all()

2024-03-28 18:40:56 发布

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

如何解决这个问题,我是在调用一个if条件的函数时得到的。我不知道我哪里出错了。任何人请引导我解决这个问题。你知道吗

    path = pd.read_csv("/home/volumata/Documents/Sangeetha/Analytics/saved-test-data/telecom_whole.csv")
    #print(orginal_telecom_whole)
orginal_telecom_80p_train, orginal_telecom_80p_test = train_test_split(path, test_size=0.20)

data =  orginal_telecom_80p_train

data = orginal_telecom_80p_test

def read_data(path, data):

    if data == 'orginal_telecom_80p_train':
        return(head_tail(data))
    elif data == 'orginal_telecom_80p_test':
        return(data_info_for_analysis(data))

    return data

    #name = input("path","data2","data1")

def head_tail(data):

    "Head of the data"

    print(orginal_telecom_80p_train.head(5))

    "Tail of the data"

    print(orginal_telecom_80p_train.tail(5))

def data_info_for_analysis(data):

    "Shape of the data"

    print(orginal_telecom_80p_test.shape)

    "data describe"

    print(orginal_telecom_80p_test.describe())

    "max & min value"

    print(orginal_telecom_80p_test.max())

    print(orginal_telecom_80p_test.min())

    "Checking the datatypes"

    print(orginal_telecom_80p_test.dtypes)


if __name__ == '__main__':
    read_data(path, data)

获取以下错误

ValueError:数据帧的真值不明确。使用a.empty、a.bool()、a.item()、a.any()或a.all()。你知道吗

如果是data=='原始电信80p\u列车',则需要显示第一个If条件部分,如果是data=='原始电信80p\u测试',则需要显示第二个If条件。你知道吗

我的示例数据集

customerID  Date    gender  age region  SeniorCitizen   Partner Dependents  tenure  PhoneService    MultipleLines   InternetService OnlineSecurity  OnlineBackup    DeviceProtection    TechSupport StreamingTV StreamingMovies Contract    PaperlessBilling    PaymentMethod   MonthlyCharges  TotalCharges    Churn
9796-BPKIW  1/2/2008    Male    57  Northeast   1   No  No  8   Yes No  Fiber optic No  No  No  No  No  No  Month-to-month  Yes Credit card (automatic) 69.95   562.7   No
4298-OYIFC  1/4/2008    Male    50  South   0   Yes No  15  Yes Yes Fiber optic No  No  Yes Yes Yes Yes Month-to-month  Yes Electronic check    103.45  1539.8  No
9606-PBKBQ  1/6/2008    Male    85  Midwest 1   Yes No  32  Yes Yes Fiber optic No  No  No  No  No  Yes Month-to-month  Yes Electronic check    85  2642.05 Yes
1704-NRWYE  1/9/2008    Female  55  Midwest 1   No  No  9   Yes No  Fiber optic No  No  No  No  Yes No  Month-to-month  Yes Electronic check    80.85   751.65  Yes
9758-MFWGD  1/6/2008    Female  52  Northeast   1   Yes Yes 48  No  No  DSL No  Yes No  No  No  No  One year    No  Bank transfer (automatic)   29.9    1388.75 No
3777-XROBG  11/20/2012  Female  57  Northeast   0   Yes Yes 58  Yes No  No  No  No  No  No  No  No  Two year    No  Credit card (automatic) 19.55   1079.65 No
5863-OOKCL  1/6/2008    Female  50  Midwest 0   No  No  10  Yes No  No  No  No  No  No  No  No  Month-to-month  No  Mailed check    18.85   163.2   No
1766-GKNMI  1/6/2008    Male    53  Northeast   0   No  No  29  Yes Yes Fiber optic No  No  No  No  No  Yes Month-to-month  Yes Electronic check    84.9    2516.2  No
2592-YKDIF  1/6/2008    Female  78  Midwest 0   No  No  1   Yes No  No  No  No  No  No  No  No  Month-to-month  No  Mailed check    20.35   20.35   No

Tags: topathnotestdatachecktrainyes
1条回答
网友
1楼 · 发布于 2024-03-28 18:40:56

您正在比较data1和data2的值,因此条件将只检查data1和data2是否不为0,您需要重新设计if条件,这应基于您如何确定data1/2具有测试或训练数据。你知道吗

相关问题 更多 >