新增同步字段
This commit is contained in:
@@ -59,17 +59,21 @@ def calc_percentile(city=None):
|
||||
|
||||
for city_now in cities:
|
||||
df = consumption_aim_df[consumption_aim_df['city'] == city_now].copy()
|
||||
for i in range(1, 100):
|
||||
df.loc[df['avg_price'] > percents_df[(percents_df['type'] == 'avg_price') & (percents_df['percent'] == i)].iloc[0]['price'],
|
||||
df['avg_price'] <= percents_df[(percents_df['type'] == 'avg_price') & (percents_df['percent'] == i + 1)].iloc[0]['price'], 'avg_price_percentile'] = 101 - i
|
||||
df['total_price'] /= 10000
|
||||
for i in range(1, 101):
|
||||
if i == 1:
|
||||
df.loc[(df['avg_price'] <= percents_df[(percents_df['type'] == 'avg_price') & (percents_df['percent'] == i)].iloc[0]['price']), 'avg_price_percentile'] = 101 - i
|
||||
|
||||
df.loc[df['total_price'] > percents_df[(percents_df['type'] == 'total_price') & (percents_df['percent'] == i)].iloc[0]['price'],
|
||||
df['total_price'] <= percents_df[(percents_df['type'] == 'total_price') & (percents_df['percent'] == i + 1)].iloc[0]['price'], 'total_price_percentile'] = 101 - i
|
||||
df.loc[(df['total_price'] <= percents_df[(percents_df['type'] == 'total_price') & (percents_df['percent'] == i)].iloc[0]['price']), 'total_price_percentile'] = 101 - i
|
||||
else:
|
||||
df.loc[(df['avg_price'] > percents_df[(percents_df['type'] == 'avg_price') & (percents_df['percent'] == i - 1)].iloc[0]['price']) & (df['avg_price'] <= percents_df[(percents_df['type'] == 'avg_price') & (percents_df['percent'] == i)].iloc[0]['price']), 'avg_price_percentile'] = 101 - i
|
||||
|
||||
df.loc[(df['total_price'] > percents_df[(percents_df['type'] == 'total_price') & (percents_df['percent'] == i - 1)].iloc[0]['price']) & (df['total_price'] <= percents_df[(percents_df['type'] == 'total_price') & (percents_df['percent'] == i)].iloc[0]['price']), 'total_price_percentile'] = 101 - i
|
||||
|
||||
# 批量更新
|
||||
for index, item in df.iterrows():
|
||||
row = dict()
|
||||
_id = str(item["_id"])
|
||||
_id = str(item["id"])
|
||||
row['total_price_percentile'] = item['total_price_percentile']
|
||||
row['avg_price_percentile'] = item['avg_price_percentile']
|
||||
|
||||
|
||||
Reference in New Issue
Block a user