[Python] raise ValueError("Cannot convert {0!r} to Excel".format(value))

Discussão em 'Python' iniciado por Stack, Maio 22, 2025.

  1. Stack

    Stack Membro Participativo

    I am trying to use the df.dropna function and I want to nest it multiple times using and by the sign ',' and or by using the sign '|' according to the docs. In my code I am converting a csv file into pandas then I am adjusting the data in the columns

    df = df[['Lastname', 'Firstname','Company','Title','Willing_to_share','Willing_to_introduce','work_phones','Work_email','Work_Street','Work_City','Work_State','Work_Zip','Personal_Street','Personal_City','Personal_State','Personal_Zip','mobile_phones','Personal_email','Note','Note_Category']]
    ##print(df)
    ## Lastname Firstname Company Title Willing_to_share \
    0 Doe Jane
    1 Malcoun Joe 8/28/2019 14:29
    2 Ramirez Morgan
    3 Burki Roman
    4 None Jordan
    5 None
    6 Zachuani Reemo
    7 Suarez Geraldo
    Willing_to_introduce work_phones Work_email \
    0 5678743546 j@greenbriar.com
    1 None ceo@nutshell.com
    2 3338765438 mramirez@nerdy.com
    3 5468756098 burki@bvb.com
    4 None jordanw45490@gmail.com
    5 None ronny
    6 None
    7 None

    Work_Street Work_City Work_State Work_Zip Personal_Street \
    0 54 George street Ridge Springs VA 25678
    1 212 South Fifth Ave Ann Arbor MI 48103
    2 567 one st Birmingham AL 45678
    3 546 fourteen street Nw Dallas TX 54678
    4
    5
    6
    7 456 yellow street

    Personal_City Personal_State Personal_Zip mobile_phones Personal_email Note \
    0 3245687907
    1 None
    2 6780431874
    3 0983457690
    4 None
    5 None
    6 None
    7 None

    Note_Category
    0
    1
    2
    3
    4
    5
    6
    7


    I have created the workbooks before the if statement

    wb = Workbook()
    ws = wb.active
    wb.title = 'Contacts'
    wb2 = Workbook()
    ws2 = wb2.active
    wb2.title = 'Contacts'


    I am putting the column headers inside the function. What I am trying to achieve is to find valid rows which must have first name, last name, and at least one phone, or address or email of any type (personal or work) not null. Then I am going to put it inside an excel datasheet. Then the inverse of the function inside a second datasheet

    r1 = df.dropna(subset=['Firstname', 'Lastname', ('work_phones' or 'mobile_phones') or (('Work_City','Work_Street','Work_State','Work_Zip') or ('Personal_Street','Personal_City','Personal_State','Personal_Zip')) or ('Work_email' or 'Personal_email')])

    for r in dataframe_to_rows(r1, index=False, header=False):
    ws2.append(r)


    wb.save("Accepted Contacts.xlsx")


    However I get this error when I run it

    raise ValueError("Cannot convert {0!r} to Excel".format(value))
    ValueError: Cannot convert ['Doe', 'Jane', nan, nan, nan, nan, '5678743546', 'j@greenbriar.com', '54 George street', 'Ridge Springs', 'VA', '25678', nan, nan, nan, nan, '3245687907', nan, nan, nan] to Excel

    Continue reading...

Compartilhe esta Página