diff --git a/dags/mt/supply/rent_avg_price.py b/dags/mt/supply/rent_avg_price.py index 32c8986..b1bcd5e 100644 --- a/dags/mt/supply/rent_avg_price.py +++ b/dags/mt/supply/rent_avg_price.py @@ -21,6 +21,8 @@ path = "/home/airflow/data/mt" output_date = sys.argv[1] if len(sys.argv) > 1 else dateutils.format_date(datetime.datetime.now(), '%Y%m') seaweed_new_result_df = pd.read_csv(path + '/FJW_COMM_' + output_date + '.csv', sep='@', encoding='utf-8') +if 'avg_price' in seaweed_new_result_df: + seaweed_new_result_df = seaweed_new_result_df.drop(columns=['avg_price', 'rent_price']) month_start = dateutils.format_date(dateutils.add_months(dateutils.parse_date(output_date, '%Y%m'), months=-1), '%Y%m') + '01' curr_month_start = output_date + '01' @@ -90,13 +92,13 @@ def format_rent(x): x.rent_price = commutils.format_rent_price(x.avg_price, x.rent_price, 1500) # 过滤租金与均价无的小区 if len(none_rent_and_price_cities) > 0: - if x['city'] in none_rent_and_price_cities and (np.isnan(x['rent_price']) and np.isnan(x['avg_price'])): + if x['city'] in none_rent_and_price_cities and (('rent_price' not in x or str(x['rent_price']) == 'nan') and ('avg_price' not in x or str(x['avg_price']) == 'nan')): x['ignore_comm'] = 1 return x result_df['ignore_comm'] = None result_df = result_df.apply(lambda x: format_rent(x), axis=1) -result_df = result_df[result_df['ignore'] != 1] +result_df = result_df[result_df['ignore_comm'] != 1] result_df.to_csv(path + '/FJW_COMM_' + output_date + '.csv', sep='@', encoding='utf-8', index=False)