Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8079823
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T16:13:56+00:00 2026-06-05T16:13:56+00:00

I have data from travel diaries which has been read in from a csv

  • 0

I have data from travel diaries which has been read in from a csv file. I have it set up as a dictionary with a bunch of lists. E.g.:

print diary['ID'][1] gives 123456789
print diary['TravelReferenceDay'][1] gives 1 for a Monday

I want to randomnly select an ID from the array based on the day e.g.:

random.choice(diary['ID']) if diary['TravelReferenceDay'] == 1

I can arrange the data by TravelReferenceDay in the csv file. I had tried the groupby method to split up the array:

groups = []
uniquekeys = []
for k, g in groupby(diary, diary['TravelReferenceDay']):
    groups.append(list(g))      # Store group iterator as a list
    uniquekeys.append(k)

But that gave the error:

TypeError: 'list' object is not callable

Could you suggest a way to achieve this? Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T16:13:58+00:00Added an answer on June 5, 2026 at 4:13 pm

    My solution with a list comprehensions:

    In [1]: import random
       ...: diary = {'ID': ['11', '22', '33', '44', '55'], 'TravelReferenceDay': [1, 1, 2, 3, 1]}
       ...: monday_diary = [x for n, x in enumerate(diary['ID']) if diary['TravelReferenceDay'][n] == 1]
    
    In [2]: monday_diary
    Out[2]: ['11', '22', '55']
    
    In [3]: random.choice(monday_diary)
    Out[3]: '22'
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have data from a CSV file that's already loaded into memory. So I
If I have data file.txt and I want to read data from it into
I have data from *.obj file. I know how draw with GL_TRIANGLES . How
I have data from tests with two lists of parts, called in and out.
I have data coming from an external system (in CSV form). The data contains
I have this data from a xml file: <?xml version=1.0 encoding=utf-8 ?> <words> <id>...</id>
I have a site that displays data on travel products from a MySQL database.
I have a MultiselectList Control (from SL toolkit) in which i have data template
I have data from two different sources that I need to combine. Some data
I need to get some data from a column. For example I have data

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.