import akshare as ak
stock_hk_spot_em_df = ak.stock_hk_spot_em()
# 计算跌幅
stock_hk_spot_em_df['跌幅'] = (stock_hk_spot_em_df['昨收'] - stock_hk_spot_em_df['最新价']) / stock_hk_spot_em_df['昨收'] * 100
# 筛选跌幅在 5% 到 8% 之间的数据
filtered_data = stock_hk_spot_em_df[(stock_hk_spot_em_df['跌幅'] >= 5) & (stock_hk_spot_em_df['跌幅'] <= 8)]
# 显示结果
filtered_data[['代码', '名称', '跌幅']]
# 计算涨幅
stock_hk_spot_em_df['涨幅'] = (stock_hk_spot_em_df['最新价'] - stock_hk_spot_em_df['昨收']) / stock_hk_spot_em_df['昨收'] * 100
# 筛选涨幅在 5% 到 8% 之间的数据
filtered_data = stock_hk_spot_em_df[(stock_hk_spot_em_df['涨幅'] >= 5) & (stock_hk_spot_em_df['涨幅'] <= 8)]
# 显示结果
filtered_data[['代码', '名称', '涨幅']]