从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]
                #去数据库中检索对象
                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

相关文章:

  • 2021-12-24
  • 2022-12-23
  • 2022-12-23
  • 2021-10-12
  • 2021-10-08
  • 2022-12-23
  • 2021-09-29
  • 2021-05-18
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-01
  • 2022-01-03
  • 2021-08-06
相关资源
相似解决方案