فهرست منبع

dataframe 中的np.nan 替换为 None,解决java解析json时报错的问题

liyuyi@c-top.com.cn 4 سال پیش
والد
کامیت
ed1b3ad502
2فایلهای تغییر یافته به همراه6 افزوده شده و 6 حذف شده
  1. 5 1
      ai_target_combine_handler.py
  2. 1 5
      time_task_create_ad_by_target.py

+ 5 - 1
ai_target_combine_handler.py

@@ -296,7 +296,7 @@ class GetTargetAndAssemblyParameters(object):
                 target_combine.update(region_dict) if 'city' in item.keys() else None
                 self.target_combine_filter_by_subset.append(target_combine)
             else:
-                logger.info("推荐定向:%s 与 账户%s 配置信息里的定向(gender:%s, age_min: %s,age_max: %s, ages_ranges:%s,region:%s )存在冲突" %
+                logger.info("推荐定向:%s 与 账户 %s 配置信息里的定向(gender:%s, age_min: %s,age_max: %s, ages_ranges:%s,region:%s )存在冲突" %
                             (item,
                              self.account_id,
                              self.advertiser_strategy['gender'],
@@ -314,6 +314,10 @@ class GetTargetAndAssemblyParameters(object):
 
         # 1-1 获取素材在该账户下关联的创意个数,过滤掉素材关联创意个数超过200的情况
         df = pd.DataFrame(self.target_combine_filter_by_subset)
+        # target_combine_filter_by_subset 转化为 dataframe 时 age_min, age_max 会填充为 np.nan,
+        # 会导致后续拼装的参数发送给java服务报错(jackson.core.JsonParseException: Non-standard token \'NaN\':)
+        # 需要把 np.nan 替换为 None
+        df.replace({np.nan: None}, inplace=True)
         # signature in ('03b93728f0d82ea7865c3c7cf632bc1b',),避免这样的sql报错
         if df.signature.nunique() == 1:
             sig_lst = tuple(list(df.signature.unique()) * 2)

+ 1 - 5
time_task_create_ad_by_target.py

@@ -65,11 +65,7 @@ acc_list = [(int(item['account_id']), int(item['project_id'])) for index, item i
 # acc_list = [(10456827, 458)]
 # acc_list = [(9774099, 458)]
 # acc_list = [(9774238, 458)]
-
-
-
-
-
+acc_list = [(9767003, 458)]
 
 
 # 2、 5个账户一组进行发送请求