take excel Data import , And want to use it echarts Visualizing , There was a mistake
class MyEncoder(json.JSONEncoder):
def default(self, obj):
if isinstance(obj, bytes):
return str(obj, encoding='utf-8')
return json.JSONEncoder.default(self, obj)
@app.route('/')
def get_data():
# Read excel data
import pandas as pd
io=r'C:\Users\86137\Desktop\python\2020 Water resources .xlsx'
work_book = pd.read_excel(io,sheet_name=0,index_col=[0],usecols=[0,4],skiprows=[0,1,2,3,4])
category=work_book.index
value = work_book.values
data={'category':category,'value':value}
return json.dumps(data,ensure_ascii=False,cls=MyEncoder, indent=4)
TypeError: Object of type Index is not JSON serializable
Added MyEncoder, But the same mistake