How to convert a two column Dataframe into a List of List

Question:

I have a coordinates dataframe with 2 columns X and Y:

X     Y
56    89
59    90
58    95
53    89
56    63
59    78

Now i want to create a List of List containing the coord. in this way to perform futher operations:

list = [(56, 89), (59, 90), (58, 95), (53, 89),....

Thanks for the help

Asked By: toms

||

Answers:

This should do what you want with your example:

[(x, y) for x, y in zip(df["X"].values, df["Y"].values)]

zip accepts more than two lists, so you can easily adapt this code to, say, 3 or more coordinates (or any other column in your dataframe).

Answered By: JustLearning
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.