-1

I am having difficulty in extracting values from a dictionary. The dictionary includes a list that contains a pair of numerical values that are of interest and my intention is to extract them and save them in a separate csv file.

The dictionary array looks like this:

{"geodesic":false, "type":"Point", "coordinates":[34.5 , 23.5]}

I am trying to get the coordinates in two separate columns. Thank you!

pd.DataFrame(mydict).to_csv('out.csv', index=False)
dataset1 = pd.read_csv('out.csv')
dataset2 = pd.DataFrame(dataset1, columns=["coordinates"])
ottomeister
  • 5,415
  • 2
  • 23
  • 27
GeorgeJ
  • 11

1 Answers1

0

All you need to do is cord_list = mydict["coordinates"].

You don't need to save it to a CSV and re-read it. You can access the variable directly from the dictionary. See here for more examples.

FYI, pd.DataFrame(dataset1, columns=["coordinates"]) is not correct code. The columns field allows you to rename columns for display purposes, it won't change how many columns are actually loaded. The current code will just load all columns again.

nareddyt
  • 1,016
  • 10
  • 20