Skip to content

Instantly share code, notes, and snippets.

@nawarazpokhrel
Created February 15, 2023 09:05
Show Gist options
  • Save nawarazpokhrel/6f1100a1c22843902a1bb1bbca54f803 to your computer and use it in GitHub Desktop.
Save nawarazpokhrel/6f1100a1c22843902a1bb1bbca54f803 to your computer and use it in GitHub Desktop.
import json
out = {}
for b, g in df.groupby("Make"):
out[b] = {
row["Model"]: {
"2021": " ".join(str(row["2021"]).split()),
"2020": " ".join(str(row["2020"]).split()),
"2019": " ".join(str(row["2019"]).split()),
"2018": " ".join(str(row["2018"]).split()),
"2017": " ".join(str(row["2017"]).split()),
"2016":" ".join(str(row["2016"]).split()),
"2015": " ".join(str(row["2015"]).split()),
}
for _, row in g.iterrows()
}
with open('/home/navaraj/Documents/new_data.json', 'w') as outfile:
json.dump(out, outfile)
from pprint import pprint
pprint(out)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment