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 read some posts, but no one helped me with my problem.
I have imported project with Maven. But Subclipse didn't recognize that project already in
I have already googled and searched stackoverflow but I can find nothing related to
I am not talking about the code editor. I have already imported my Visual
I am looking to merge multiple xslt stylesheets (V1.0) into one stylesheet. I have
I've imported a datset into Rapidminer 5 and one of the columns that was
I am invoking HTTPS SOAP web service through java code. I have already imported
I have already pushed all the changes to the server. Here is the order
I have already download and install this package to support HTML5 input type http://support.microsoft.com/kb/2468871
I have already tried multiple ways. defaults write com.apple.Xcode PBXCustomTemplateMacroDefinitions '{ORGANIZATIONNAME=YourNameHere;}' Also i've tried

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.