Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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

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

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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).

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading