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 978587
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T04:04:48+00:00 2026-05-16T04:04:48+00:00

So I have already imported one XML-ish file with 3000 elements and parsed them

  • 0

So I have already imported one XML-ish file with 3000 elements and parsed them into a CSV for output. But I also need to import a second CSV file with ‘keyword’,’latitude’,’longitude’ as columns and use it to add the GPS coordinates to additional columns on the first file.

Reading the python tutorial, it seems like {dictionary} is what I need, although I’ve read on here that tuples might be better. I don’t know.

But either way – I start with:

    floc = open('c:\python\kenya_location_lookup.csv','r')
    l = csv.DictReader(floc)
    for row in l: print row.keys()

The output look like:

{‘LATITUDE’: ‘-1.311467078’, ‘LONGITUDE’: ‘36.77352011’, ‘KEYWORD’: ‘Kianda’}
{‘LATITUDE’: ‘-1.315288401’, ‘LONGITUDE’: ‘36.77614331’, ‘KEYWORD’: ‘Soweto’}
{‘LATITUDE’: ‘-1.315446430425027’, ‘LONGITUDE’: ‘36.78170621395111’, ‘KEYWORD’: ‘Gatwekera’}
{‘LATITUDE’: ‘-1.3136151425171327’, ‘LONGITUDE’: ‘36.785863637924194’, ‘KEYWORD’: ‘Kisumu Ndogo’}

I’m a newbie (and not a programmer). Question is how do I use the keys to pluck out the corresponding row data and match it against words in the body of the element in the other set?

  • 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-05-16T04:04:49+00:00Added an answer on May 16, 2026 at 4:04 am

    If you dump the DictReader into a list (data = [row for row in csv.DictReader(file)]), and you have unique keywords for each row, convert that list of dictionaries into a dictionary of dictionaries, using that keyword as the key.

    >>> data = [row for row in csv.DictReader(open('C:\\my.csv'),
    ...                                       ('num','time','time2'))]
    >>> len(data)  # lots of old data :P
    1410
    >>> data[1].keys()
    ['time2', 'num', 'time']
    >>> keyeddata = {}
    >>> for row in data[2:]:  # I have some junk rows
    ...     keyeddata[row['num']] = row
    ...
    >>> keyeddata['32']
    {'num': '32', 'time2': '8', 'time': '13269'}
    

    Once you have the keyword pulled out, you can iterate through your other list, grab the keyword from it, and use it as the index for the lat/long list. Pull out the lat/long from that index and add it to the other list.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have already posted something similar here but I would like to ask the
The basics have already been answered here . But is there a pre-built PHP
I know I have already answered a similar question ( Running Batch File in
I've imported a datset into Rapidminer 5 and one of the columns that was
I have already tried PreRenderComplete and unload is too late
I have already googled for this I have a Table with following structure in
I have a repository which I have already cloned from Subversion. I've been doing
In .NET I have already tried the configuration below successfully: <system.net> <connectionManagement> <add address=*
I believe several of us have already worked on a project where not only
OK, I know there have already been questions about getting started with TDD ..

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.