Skip to content

Instantly share code, notes, and snippets.

@laixintao
Created November 3, 2017 02:55
Show Gist options
  • Save laixintao/666f2af2ed7dc34cf74471c64984e5b2 to your computer and use it in GitHub Desktop.
Save laixintao/666f2af2ed7dc34cf74471c64984e5b2 to your computer and use it in GitHub Desktop.
xlsx to json
# -*- coding: utf-8 -*-
"""将excel转换成json"""
import json
import pandas
import numpy
courts = pandas.read_excel("courts.xlsx")
name_mapping = {}
for court in courts.iterrows():
stand_name = ""
for value in court[1]:
if not stand_name:
stand_name = value
names = name_mapping.setdefault(stand_name, [])
if not pandas.isnull(value):
names.append(value)
print(json.dumps(name_mapping, indent=2, ensure_ascii=False))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment