涉及到的方法

apply

示例代码

  1. def function(x, types):
  2. if types == "title":
  3. return "%s-%s栋%s%s号" % (x["区域"], x["ridgepole_num"],
  4. x["房屋分类"], x["house_num"])
  5. else:
  6. raise Exception500000("不在枚举范围内")
  7. res_df = pd.DataFrame(queryset)
  8. # 示例一
  9. res_df["区域"] = res_df.region.apply(lambda x: dict(region_choices)[x])
  10. # 示例二
  11. res_df["标题"] = res_df.apply(lambda x: function(x, "title"), axis=1)