1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

[Python] How to filter out elements with No Value for certain field

Discussão em 'Python' iniciado por Stack, Setembro 23, 2024.

  1. Stack

    Stack Membro Participativo

    I have a list of Events in Python. The problem i have is that a lot of events don't contain an event_data['pick']['blurb']. How do I create a filtered list with just the events that have this data?

    Current code shows error

    if event["event"]['pick']['blurb'] in events:
    TypeError: 'NoneType' object is not subscriptable


    with open(output_file, "w", newline="", encoding="utf-8") as file:
    writer = csv.writer(file)
    writer.writerow(["Event name", "Date", "Start Time", "End Time",
    "Artists", "Images", "Image", "Blurb", "Venue"])

    filtered = []
    for event in events:
    if event["event"]['pick']['blurb'] in events:
    filtered.append(event)
    # print(filtered)



    for event in filtered:
    event_data = event["event"]
    writer.writerow([event_data['title'],
    event_data['date'],
    event_data['startTime'],
    event_data['endTime'],
    ', '.join([artist['name'] for artist in event_data['artists']]),
    ', '.join([images['filename'] for images in event_data['images']]),
    event_data['images'][0]['filename'],
    **event_data['pick']['blurb'],**
    event_data['venue']['name']])

    Continue reading...

Compartilhe esta Página