从numpy的int64 转化成的decimal是不支持的,意思就是说不能直接转换。

df_datas = pd.read_excel(excel_file)
            nrows=df_datas.shape[0]
            ncols=df_datas.columns.size
            index_list = df_datas.index
            for index in index_list:
                data = df_datas.loc[index]
                #去PowerPlant表中检索电厂ID和表中的ID值的电厂信息
                obj = PowerPlant.objects.filter(plant_id = data.id).first()
                #写入到数据库
                PowerPlant.objects.create(
                                time = data.time,
                                plant_id=data.id,
                                plant_name = obj.plant_name,
                                plant_type = obj.plant_type,
                                plant_capacity = obj.plant_capacity,
                                plant_status = obj.plant_status,
                                plant_generated_energy=data.output.astype(Decimal),
                                plant_electrical_consumption=data.consumption.astype(Decimal),
                                plant_standard_coal_consumption=data.standard.astype(Decimal),
                                plant_raw_coal_consumption=data.raw.astype(Decimal),
                                plant_fuel_consumption=data.fuel.astype(Decimal))

            data = {'code':200,'msg':"批量上报成功!"}
            return JsonResponse(data)

这里使用了.astype(Decimal)进行格式转换成float

12-23 17:10