008.py

题目:输出9*9口诀。

#常规方法。。。

r=range(1,10)
for x in r:
    for y in range(1,x+1):
        print(y,'*',x,'=',x*y)
    print('\n')   
       

 

#看到的大神方法。。。

 

 

print('\n'.join([ ' '.join([ "%d*%d=%2s" %(y,x,x*y) for y in range(1,x+1)]) for x in range(1,10)]))

#join()是字符串操作函数,将字符串、元组、列表中的元素以指定的字符(分隔符)连接生成一个新的字符串

#上例中,外层用换行符分割,内层用空格分割,

 

C:\python\py\.venv\Scripts\python.exe C:\python\py\7.22.py === 因素筛选结果(不显示 0.00) === 心率: rpb=-0.01, P=0.80 血氧饱和度: rpb=0.02, P=0.39 GCS评分: rpb=0.04, P=0.08 转运时长: rpb=0.01, P=0.77 镇静剂使用: rpb=-0.03, P=0.29 呼吸支持: rpb=-0.00, P=0.88 年龄: rpb=0.01, P=0.84 APACHE II评分: rpb=0.03, P=0.29 === VIF共线性分析 === 特征 VIF值 0 心率 17.976832 1 血氧饱和度 42.486776 2 GCS评分 7.331784 3 转运时长 6.108660 4 镇静剂使用 2.009300 5 呼吸支持 2.615991 6 年龄 16.590947 7 APACHE II评分 3.918573 C:\python\py\7.22.py:160: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]` C:\python\py\7.22.py:160: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]` C:\python\py\7.22.py:160: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]` C:\python\py\7.22.py:160: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]` C:\python\py\7.22.py:160: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]` C:\python\py\7.22.py:160: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]` C:\python\py\7.22.py:160: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]` C:\python\py\7.22.py:160: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]` C:\python\py\7.22.py:160: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]` C:\python\py\7.22.py:160: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]` C:\python\py\7.22.py:160: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]` C:\python\py\7.22.py:160: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]` C:\python\py\7.22.py:160: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]` C:\python\py\7.22.py:160: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]` C:\python\py\7.22.py:160: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]` C:\python\py\7.22.py:160: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]` C:\python\py\7.22.py:160: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]` C:\python\py\7.22.py:160: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]` C:\python\py\7.22.py:160: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]` C:\python\py\7.22.py:160: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]` C:\python\py\7.22.py:160: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]` C:\python\py\7.22.py:160: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]` C:\python\py\7.22.py:160: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]` C:\python\py\7.22.py:160: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]` C:\python\py\7.22.py:160: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]` C:\python\py\7.22.py:160: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]` === 显著直接关联(偏相关|r|>0.001) === 心率 与 转运后不良事件: r=-0.006 血氧饱和度 与 转运后不良事件: r=0.022 GCS评分 与 转运后不良事件: r=0.045 转运时长 与 转运后不良事件: r=0.009 镇静剂使用 与 转运后不良事件: r=-0.029 呼吸支持 与 转运后不良事件: r=-0.002 年龄 与 转运后不良事件: r=0.008 APACHE II评分 与 转运后不良事件: r=0.031 === 节点核心度排序 === APACHE II评分: 0.378 年龄: 0.295 血氧饱和度: 0.267 GCS评分: 0.261 adverse_event: 0.254 转运时长: 0.249 心率: 0.198 镇静剂使用: 0.190 呼吸支持: 0.097 C:\python\py\7.22.py:160: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]` C:\python\py\7.22.py:160: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]` C:\python\py\7.22.py:160: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]` C:\python\py\7.22.py:160: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]` C:\python\py\7.22.py:160: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]` C:\python\py\7.22.py:160: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]` C:\python\py\7.22.py:160: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]` C:\python\py\7.22.py:160: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]` C:\python\py\7.22.py:160: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]` C:\python\py\7.22.py:160: FutureWarning: Series.__getitem__ treating keys as positions is deprecated. In a future version, integer keys will always be treated as labels (consistent with DataFrame behavior). To access a value by position, use `ser.iloc[pos]` Traceback (most recent call last): File "C:\python\py\7.22.py", line 220, in <module> nx.draw_networkx_edges(G, pos, ~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^ edge_color=edge_colors, ^^^^^^^^^^^^^^^^^^^^^^^ ...<2 lines>... arrowsize=15, ^^^^^^^^^^^^^ zorder=0) ^^^^^^^^^ TypeError: draw_networkx_edges() got an unexpected keyword argument 'zorder'
最新发布
07-24
<think>好的,用户提供的Python代码在运行时遇到了错误,具体是`TypeError: draw_networkx_edges() got an unexpected keyword argument 'zorder'`。我需要分析这个问题并提供解决方案。 首先,用户使用的是networkx的`draw_networkx_edges`函数,但传递了`zorder`参数,而该函数可能不支持这个参数。查看networkx的文档,确认`draw_networkx_edges`的参数列表,发现确实没有`zorder`这个参数。`zorder`通常用于matplotlib的绘图函数中,用于控制元素的绘制顺序。用户可能误以为`draw_networkx_edges`支持这个参数,导致错误。 接下来,用户希望调整图形的层次,使得文字在边线之上。正确的做法应该是使用matplotlib的`zorder`参数在`draw_networkx_labels`中设置,或者在绘制节点和边的时候通过分层调用绘图函数来控制顺序。例如,先绘制边,再绘制节点,最后绘制标签,这样标签自然会在最上层。此外,用户可能在`draw_networkx_edges`中错误地添加了`zorder`,需要删除这个参数,并确保各个元素的绘制顺序正确。 另外,用户代码中还有多个FutureWarning,提示在未来的pandas版本中,使用整数作为位置索引可能会被弃用。需要检查代码中使用Series的位置索引的地方,例如在循环中使用`for i in range(len(df))`时,应该改用`.iloc`来访问数据,以避免未来的兼容性问题。 总结问题,用户需要解决的主要问题有: 1. `draw_networkx_edges`不支持`zorder`参数,导致TypeError。 2. 未来警告提示需要修改代码以避免使用位置索引。 3. 图形绘制顺序可能需要调整,以确保标签在最上层。 解决方案包括: - 移除`draw_networkx_edges`中的`zorder`参数。 - 调整绘图顺序,先绘制边,再绘制节点,最后绘制标签,利用matplotlib的默认zorder。 - 检查并修改所有使用整数索引访问Series的地方,改用`.iloc`或明确使用标签。 此外,用户可能还希望进一步优化图表的可读性,比如调整节点大小、边线宽度、字体大小等,这些已经在之前的修改中处理过,但需要确保所有参数正确应用。</think>出现错误的原因是 `networkx.draw_networkx_edges()` 不支持 `zorder` 参数。以下是修复后的完整代码(仅修改出错部分): ```python # 网络可视化修复版 pos = nx.spring_layout(G, k=0.8, seed=42) plt.figure(figsize=(16, 10)) # 节点颜色映射 color_map = [] for node in G.nodes: if node in T0_nodes: color_map.append((0.8, 0.9, 1)) elif node in T1_nodes: color_map.append((0.9, 0.8, 1)) elif node in T2_nodes: color_map.append((1, 0.8, 0.8)) # 边颜色设置 edge_colors = ['red' if G[u][v]['weight'] > 0 else 'blue' for u, v in G.edges] # 绘制网络图(调整绘制顺序) # 1. 绘制边 nx.draw_networkx_edges(G, pos, edge_color=edge_colors, width=[abs(G[u][v]['weight']) * 10 for u, v in G.edges], arrowsize=15, alpha=0.8) # 2. 绘制节点 nx.draw_networkx_nodes(G, pos, node_color=color_map, node_size=[core * 150 for core in node_core.values()], alpha=0.9) # 3. 单独绘制标签(默认zorder最高) nx.draw_networkx_labels(G, pos, font_size=14, font_weight='bold') # 添加标题和图例 plt.title('转运后不良事件动态关联网络', fontsize=18, pad=20) plt.legend(handles=[ plt.Line2D([0], [0], color='red', lw=2, label='正相关'), plt.Line2D([0], [0], color='blue', lw=2, label='负相关') ], loc='upper right', fontsize=12) plt.axis('off') plt.tight_layout() plt.show() ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值