0

Actually, I am facing the problem to add the data in the subcolumn in the specific format. I have created the "Polypoints" as the main column and I want

df["Polypoints"] = [{"__type":"Polygon","coordinates":Row_list}]

where Row_list is the column of dataframe which contains the data in the below format

df["Row_list"] = [[x1,y1],[x2,y2],[x3,y3]
                 [x1,y1],[x2,y2],[x3,y3]
                 [x1,y1],[x2,y2],[x3,y3]]

I want to convert the dataframe into json in the format "Polypoints" :{"__type":"Polygon" ,"coordinates":Row_list}

bharatk
  • 3,964
  • 5
  • 13
  • 28
P.D
  • 135
  • 5
  • I have added the list in the Dataframe column "Row_list" – P.D Sep 26 '19 at 04:41
  • I have to add one more column "Polypoints" in the Dataframe as specified above and add the data of Row_list column in the "coordinates" subcolumn. – P.D Sep 26 '19 at 04:42
  • 1
    Try the `json` or `jsonpickle` packages. E.g. `json.dumps(df)`. – André Müller Sep 26 '19 at 04:50
  • Base on the question https://stackoverflow.com/questions/58091927/how-to-concatenate-pairs-of-row-elements-into-a-new-column-in-a-pandas-dataframe I have issue related to the above answer. Please check the link and suggest for the issue – P.D Sep 26 '19 at 04:58
  • Did you try `json` like proposed in comment above? It sounds to me like a good option... – Itamar Mushkin Sep 26 '19 at 05:53
  • before json I have to create one column in the dataframe "Polypoint" specified in the above format – P.D Sep 26 '19 at 06:01
  • The DataFrame Column "Polypoints" once created in the specific format then it is easier to directly get the json file. – P.D Sep 26 '19 at 06:05
  • try `df['Polypoints'] = df.apply(lambda row: {"__type":"Polygon", "coordinates":row['Row_list']} ,axis=1)` – Itamar Mushkin Sep 26 '19 at 06:06
  • Thanks, Itamar your solution works for me – P.D Sep 26 '19 at 06:10
  • Also suggest for the question posted at https://stackoverflow.com/questions/58112213/how-to-read-the-sublist-from-the-main-list-and-add-the-sublist-in-the-another-da – P.D Sep 26 '19 at 09:50

0 Answers0