AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / user-10722752

Karthik S's questions

Martin Hope
Karthik S
Asked: 2025-01-07 18:07:29 +0800 CST

使用 np.select 函数进行 group by apply 时出现奇怪的输出

  • 6

我正在处理时间序列数据,其中我尝试使用 IQR 方法执行异常值检测。

示例数据:

import pandas as pd
import numpy as np

df = pd.DataFrame({'datecol' : pd.date_range('2024-1-1', '2024-12-31'),
                   'val' : np.random.random.randin(low = 100, high = 5000, size = 8366})

我的功能:

def is_outlier(x):
    iqr = x.quantile(.75) - x.quantile(.25)
    outlier = (x <= x.quantile(.25) - 1.5*iqr) | (x >= x.quantile(.75) + 1.5*iqr)
    return np.select([outlier], [1], 0)

df.groupby(df['datecol'].dt.weekday)['val'].apply(is_outlier)

输出类似如下内容:

0    [1,1,0,0,....
1    [1,0,0,0,....
2    [1,1,0,0,....
3    [1,0,1,0,....
4    [1,1,0,0,....
5    [1,1,0,0,....
6    [1,0,0,1,....

我期望单个系列作为输出,我可以将其dataframe作为标志列添加回原始系列。

有人可以帮我吗?

python
  • 1 个回答
  • 44 Views
Martin Hope
Karthik S
Asked: 2024-12-30 19:25:55 +0800 CST

获取 AttributeError:部分初始化的模块“numpy.core.arrayprint”没有属性“array2string”(很可能是由于循环导入)错误

  • 5

我尝试安装 pandarallel,但由于某些错误而无法安装。现在,当我尝试简单地导入 pandas 和 numpy 时,我收到错误:

import pandas as pd
import numpy as np

AttributeError: partially initialized module 'numpy.core.arrayprint' has no attribute 'array2string' (most likely due to circular import)

如果我尝试导入 pandas 或 numpy,就会出现此错误。我查找了其他类似partially initialied module错误的答案,尝试重命名numpy文件,但仍然无法解决问题。我尝试numpy使用进行升级pip,但仍然没有帮助。

有人可以帮我解决这个错误吗?

python
  • 1 个回答
  • 30 Views
Martin Hope
Karthik S
Asked: 2024-11-15 22:26:58 +0800 CST

如何根据百分位范围为 Pandas 列中的每个值分配分数,得到“系列的真值不明确。”错误

  • 6

我需要为 pandas 数据框的许多列中的每个值分配分数,具体取决于每个值之间的百分位数分数范围。

我创建了一个函数:

import pandas as pd
import numpy as np

def get_percentiles(x, percentile_array):
    percentile_array = np.sort(np.array(percentile_array))
    if x < x.quantile(percentile_array[0]) < 0:
        return 1
    elif (x >= x.quantile(percentile_array[0]) & (x < x.quantile(percentile_array[1]):
        return 2
    elif (x >= x.quantile(percentile_array[1]) & (x < x.quantile(percentile_array[2]):
        return 3
    elif (x >= x.quantile(percentile_array[2]) & (x < x.quantile(percentile_array[3]):
        return 4
    else:
        return 5

样本数据:

df = pd.DataFrame({'col1' : [1,10,5,9,15,4],
                   'col2' : [4,10,15,19,3,2],
                   'col3' : [10,5,6,9,1,24]})

当我尝试使用 apply 运行该函数时:

percentile_array = [0.05, 0.25, 0.5, 0.75]

df.apply(lambda x : get_percentiles(x, percentile_array), result_type = 'expand')

我收到以下错误:

Truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all()

预期输出是包含 3 列的新数据框,其分数介于 1 到 5 之间,具体取决于每列中每个值属于哪个百分位范围

python
  • 1 个回答
  • 23 Views
Martin Hope
Karthik S
Asked: 2024-06-25 13:37:30 +0800 CST

'azureml.pipeline' 和 azureml.widgets 均出现 ModuleNotFoundError

  • 5

尝试导入PythonScriptStep和RunDetails使用时:

from azureml.pipeline.steps import PythonScriptStep
from azureml.widgets import RunDetails

获取ModuleNotFoundError: No module named 'azureml.pipeline' ModuleNotFoundError:没有名为“azureml.widgets”的模块错误

我尝试使用以下方法手动安装 azureml 管道:

!pip install azureml-pipeline

出现各种不兼容错误:

ERROR: ray 2.0.0 has requirement click<=8.0.4,>=7.0, but you'll have click 8.1.3 which is incompatible.
ERROR: ray 2.0.0 has requirement grpcio<=1.43.0,>=1.28.1; python_version < "3.10", but you'll have grpcio 1.54.2 which is incompatible.
ERROR: pyopenssl 23.0.0 has requirement cryptography<40,>=38.0.0, but you'll have cryptography 42.0.8 which is incompatible.
ERROR: jupyterlab-server 2.23.0 has requirement jinja2>=3.0.3, but you'll have jinja2 2.11.2 which is incompatible.
ERROR: datasets 2.3.2 has requirement dill<0.3.6, but you'll have dill 0.3.6 which is incompatible.
ERROR: dask-sql 2023.6.0 has requirement pandas>=1.4.0, but you'll have pandas 1.1.5 which is incompatible.
ERROR: azureml-widgets 1.56.0 has requirement azureml-core~=1.56.0, but you'll have azureml-core 1.51.0.post1 which is incompatible.
ERROR: azureml-widgets 1.56.0 has requirement azureml-telemetry~=1.56.0, but you'll have azureml-telemetry 1.51.0 which is incompatible.
ERROR: azureml-inference-server-http 0.8.4 has requirement flask<2.3.0, but you'll have flask 2.3.2 which is incompatible.
ERROR: azure-cli 2.49.0 has requirement azure-keyvault-keys==4.8.0b2, but you'll have azure-keyvault-keys 4.8.0 which is incompatible.
ERROR: azure-cli 2.49.0 has requirement azure-mgmt-keyvault==10.2.0, but you'll have azure-mgmt-keyvault 10.2.1 which is incompatible.
ERROR: azure-cli 2.49.0 has requirement azure-mgmt-resource==22.0.0, but you'll have azure-mgmt-resource 21.1.0b1 which is incompatible.
ERROR: azure-cli-core 2.49.0 has requirement msal[broker]==1.20.0, but you'll have msal 1.22.0 which is incompatible.
ERROR: autokeras 1.0.16 has requirement tensorflow<=2.5.0,>=2.3.0, but you'll have tensorflow 2.11.0 which is…
Show all (20.4 kB)

有人可以帮我解决这些错误吗?

  • 1 个回答
  • 27 Views
Martin Hope
Karthik S
Asked: 2023-08-17 17:54:51 +0800 CST

如何检查 Pandas DataFrame 中的所有浮点列是否近似相等或接近

  • 5

我有一个包含 12 列的数据框。在这些列中,我有许多浮动列,我需要验证这些值是否大致相等或足够接近。

样本数据:

df = pd.DataFrame({'id' : ['abc', 'pqr', 'xyz', 'cbz'],
                  'col1' : [0.0234, 0.001852, 4.123, 0.0012],
                  'col2' : [0.0235, 0.001851, 0.0123, 0.0013],
                  'col3' : [0.0233, 0.001849, 0.124, 0.0011]})
df

    id  col1      col2      col3
0   abc 0.0234    0.0235    0.0233
1   pqr 0.001852  0.001851  0.001849
2   xyz 4.123     0.0123    0.124

我可以使用np.isclose并设置一个适用于我的情况的阈值,即 0.062。但是有人可以告诉我如何比较 col1 约等于 col2 约等于 col3 吗?如果甚至有 1 列不满足条件,则结果应False与 的情况相同id xyz。

python
  • 3 个回答
  • 42 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    重新格式化数字,在固定位置插入分隔符

    • 6 个回答
  • Marko Smith

    为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会?

    • 2 个回答
  • Marko Smith

    VScode 自动卸载扩展的问题(Material 主题)

    • 2 个回答
  • Marko Smith

    Vue 3:创建时出错“预期标识符但发现‘导入’”[重复]

    • 1 个回答
  • Marko Smith

    具有指定基础类型但没有枚举器的“枚举类”的用途是什么?

    • 1 个回答
  • Marko Smith

    如何修复未手动导入的模块的 MODULE_NOT_FOUND 错误?

    • 6 个回答
  • Marko Smith

    `(表达式,左值) = 右值` 在 C 或 C++ 中是有效的赋值吗?为什么有些编译器会接受/拒绝它?

    • 3 个回答
  • Marko Smith

    在 C++ 中,一个不执行任何操作的空程序需要 204KB 的堆,但在 C 中则不需要

    • 1 个回答
  • Marko Smith

    PowerBI 目前与 BigQuery 不兼容:Simba 驱动程序与 Windows 更新有关

    • 2 个回答
  • Marko Smith

    AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String”

    • 1 个回答
  • Martin Hope
    Fantastic Mr Fox msvc std::vector 实现中仅不接受可复制类型 2025-04-23 06:40:49 +0800 CST
  • Martin Hope
    Howard Hinnant 使用 chrono 查找下一个工作日 2025-04-21 08:30:25 +0800 CST
  • Martin Hope
    Fedor 构造函数的成员初始化程序可以包含另一个成员的初始化吗? 2025-04-15 01:01:44 +0800 CST
  • Martin Hope
    Petr Filipský 为什么 C++20 概念会导致循环约束错误,而老式的 SFINAE 不会? 2025-03-23 21:39:40 +0800 CST
  • Martin Hope
    Catskul C++20 是否进行了更改,允许从已知绑定数组“type(&)[N]”转换为未知绑定数组“type(&)[]”? 2025-03-04 06:57:53 +0800 CST
  • Martin Hope
    Stefan Pochmann 为什么 {2,3,10} 和 {x,3,10} (x=2) 的顺序不同? 2025-01-13 23:24:07 +0800 CST
  • Martin Hope
    Chad Feller 在 5.2 版中,bash 条件语句中的 [[ .. ]] 中的分号现在是可选的吗? 2024-10-21 05:50:33 +0800 CST
  • Martin Hope
    Wrench 为什么双破折号 (--) 会导致此 MariaDB 子句评估为 true? 2024-05-05 13:37:20 +0800 CST
  • Martin Hope
    Waket Zheng 为什么 `dict(id=1, **{'id': 2})` 有时会引发 `KeyError: 'id'` 而不是 TypeError? 2024-05-04 14:19:19 +0800 CST
  • Martin Hope
    user924 AdMob:MobileAds.initialize() - 对于某些设备,“java.lang.Integer 无法转换为 java.lang.String” 2024-03-20 03:12:31 +0800 CST

热门标签

python javascript c++ c# java typescript sql reactjs html

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve