將excel的數據導入,並想用echarts進行可視化,出現了錯誤
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():
# 讀取excel數據
import pandas as pd
io=r'C:\Users\86137\Desktop\python\2020水資源.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
添加了MyEncoder,但還是同樣的錯誤