财力评级统计优化
This commit is contained in:
@@ -23,10 +23,10 @@ nextcloud_aim_file_path = '财力评级/财力评级/财力评级统计报表'
|
||||
|
||||
|
||||
def stat(community_summary_df):
|
||||
grouped = community_summary_df.groupby(["city", "region"])
|
||||
grouped = community_summary_df.groupby(["city"])
|
||||
|
||||
results = []
|
||||
for (city, region), group in grouped:
|
||||
for item, group in grouped:
|
||||
# 计算财力评级指标
|
||||
rating_counts = group["consumption_rating"].value_counts(normalize=True)
|
||||
rating_1 = rating_counts.get(1, 0)
|
||||
@@ -48,8 +48,7 @@ def stat(community_summary_df):
|
||||
confidence_counts = group["credit"].value_counts(normalize=True)
|
||||
|
||||
results.append({
|
||||
"城市": city,
|
||||
"区域": region,
|
||||
"城市": item[0],
|
||||
"财力评级1级占比": round(rating_1 * 100, 1),
|
||||
"财力评级1级分数范围": f"{rating_1_scores.min():.0f}-{rating_1_scores.max():.0f}" if not rating_1_scores.empty else "-",
|
||||
"财力评级2级占比": round(rating_2 * 100, 1),
|
||||
@@ -124,7 +123,15 @@ def detail(city):
|
||||
community_summary_df = data_utils.flatten_json(community_summary_df, 'credit_detail')
|
||||
community_summary_df['diff'] = np.abs(community_summary_df['consumption_rating'] - community_summary_df['price_rating'])
|
||||
community_summary_df['total_price_diff'] = np.abs(community_summary_df['consumption_rating'] - community_summary_df['total_price_rating'])
|
||||
community_summary_df['estate_charge_type'] = np.where(community_summary_df['estate_charge_flag'] == 1,'周边','自有')
|
||||
community_summary_df['estate_charge_type'] = np.where(
|
||||
pd.notna(community_summary_df['estate_charge']), # 仅当 estate_charge 不为空时处理
|
||||
np.where(
|
||||
community_summary_df['estate_charge_flag'] == 1,
|
||||
'周边',
|
||||
'自有'
|
||||
),
|
||||
np.nan # 如果 estate_charge 为空,则返回 NaN
|
||||
)
|
||||
|
||||
community_summary_df['credit'] = np.where(community_summary_df['total_price_diff'] == 0, '高', np.where(community_summary_df['total_price_diff'] == 1, '中', np.where(community_summary_df['total_price_diff'] >= 2, '低', '-')))
|
||||
stat(community_summary_df)
|
||||
|
||||
Reference in New Issue
Block a user