python - 在 Excel 或 Jupyter 中对范围内的相关矩阵进行排序
问题描述
我有一个使用以下代码导出的大数据集:
(corr.style.background_gradient(cmap='coolwarm').to_excel("S:.......ABC.xlsx", engine="openpyxl"))
我如何拥有介于 1 到 -1 之间的大量数据,而我只想要范围为 0.3 到 0.933 和 -0.3 到 -0.933 的数据。
我该怎么做?
例如数据:
解决方案
您可以首先找到列以保持所有值都在这样的范围内
columns_to_keep1 = [col for col in corr.columns if not (any(corr[col] < 0.3) or any(corr[col] > 0.933))]
columns_to_keep2 = [col for col in corr.columns if not (any(corr[col] > -0.3) or any(corr[col] < -0.933))]
上面的代码片段将检查数据框中的所有列,并仅将所有值都在所需范围内的那些列添加到最终列表(通过列表理解)。
然后你可以columns_to_keep
像这样只从你的数据框中选择列
corr = corr[columns_to_keep1 + columns_to_keep2]
推荐阅读
- python - FileChooserDialog 在函数退出之前不会关闭。- 蟒蛇GTK
- erlang - Dialyzer 警告 no_exit 构建不良记录 - 这是一个错误吗?
- java - 注册表仅在用户已登录时才有效
- lua - Lua 中的这个“选择”函数总是返回 nil
- algorithm - 如何编写一个算法来交换两个变量而不创建第三个变量?
- python - Disocrd.py 命令
- eclipse - “Eclipse XSL 开发人员工具”支持 XSLT 3.0 和 XPath 3.1
- ios - 在 ios AVPlayer 中切换 HLS 流的比特率
- react-native - React Native Redux 条件渲染
- maven - 如何优先使用多个 Maven 本地存储库