0

I have a data set that consists of two columns as coordinates. I would like to import them to python under one header list called "coordinates". Does anyone have any solution?. Thanks!

2 Answers2

1

You can use: df.values.tolist().

First select the columns from the name of your dataframe:

df = pd.DataFrame(name_of_dataframe, columns= ['col1', 'col2'])

Next change it to a list: list = df.values.tolist().

Then flatten the list with a loop appending each smaller list into one bigger list.

triedit
  • 169
  • 1
  • 9
1

You can use list comprehension with csv module.

import csv

with open('filename.csv') as file:
    coordinates = [(float(x), float(y)) for x, y in csv.reader(file, delimiter= ',')]
Shivam Miglani
  • 542
  • 3
  • 9