python - 数据框的标准差?

标签 python pandas dataframe

由于 dataframe.std() 已弃用,我们现在应该使用 groupby:https://pandas.pydata.org/docs/reference/api/pandas.core.groupby.GroupBy.std.html

但是,为了找到这个的简单标准差

dataframe['number'].std(),

groupby 函数对我来说似乎是一个不必要的长命令。 “dataframe”有一列“数字”,范围从 1 到 100。

使用 groupby 时上面的行会是什么样子?

最佳答案

我认为对docs存在误解。 .

pandas 所弃用的具体是 level参数有利于其 groupby counterpart (您分享的链接)。没有任何地方写着pandas.Series.std整体已弃用:

level: int or level name, default None If the axis is a MultiIndex (hierarchical), count along a particular level, collapsing into a scalar.

Deprecated since version 1.3.0: The level keyword is deprecated. Use groupby instead.

和:

numeric_only: bool, default None Include only float, int, boolean columns. If None, will attempt to use everything, then use only numeric data. Not implemented for Series.

Deprecated since version 1.5.0: Specifying numeric_only=None is deprecated. The default value will be False in a future version of pandas.

鉴于您建议的代码行,我认为没有理由更改它。继续使用:

df['col'].std()

关于python - 数据框的标准差?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74215072/

相关文章:

python - python 中的单元测试网络抓取工具

尝试解析 JSON 推文时出现 Python 编码问题

Python:如何创建一个循环来更改经度数据

python - 为什么在 Pandas 数据框中应用有时并不比 for 循环快?

python - 从字典中选择值以创建新的 DataFrame 列

python - Unpivot Pandas 数据

c++ - 从命令行 Python/C++ 启动 Minecraft

python - 创建新列,其中两个不同数据帧的两列相同

python - 计算值并将值放入 M​​ultiIndex Pandas DataFrame 的二级列中

python : Function which works on initial/default values if no parameters are passed