0

I have a .csv file with two columns of interest 'latitude' and 'longitude' with populated values

I would like to return [latitude, longitude] pairs of each row from the two columns as lists...

[10.222, 20.445] [10.2555, 20.119] ... and so forth for each row of my csv...

The problem with > import pandas colnames = [ 'latitude', 'longitude'] data = pandas.read_csv('path_name.csv', names=colnames)

latitude = data.latitude.tolist()
longitude = data.longitude.tolist()

is that it creates two lists for all the values each latitude and longitude column

How can I create lists for each latitude, longitude pair in python ?

0

2 Answers 2

1

Most basic way

import csv
with open('filename.txt', 'r') as csvfile:
     spamreader = csv.reader(csvfile)
     for row in spamreader:
         print row
Sign up to request clarification or add additional context in comments.

1 Comment

Not quite what I'm looking for, it still returns two lists, one of all values in latitude and another of all values in longitude...
0

So from what I understand is that you want many lists of two elements: lat and long. However what you are receiving is two lists, one of lat and one of long. what I would do is loop over the length of those lists and then take that element in the lat/long lists and put them together in their own list.

for x in range(0, len(latitude)):
    newList = [latitude[x], longitude[x]]

2 Comments

Yes, the idea is to create list pairs based on same indexes.
Did this help you at all?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.