python - Python:数据框列表中的标准偏差
问题描述
我有一个说 50 个数据帧“list1”的列表,每个数据帧都有“速度”和“值”列,就像这样;
Speed Value
1 12
2 17
3 19
4 21
5 25
我正在尝试获取所有数据帧中每种速度的“值”的标准偏差。最终目标是获得每个速度的标准偏差列表或 df,如下所示;
Speed Standard Deviation
1 1.23
2 2.5
3 1.98
4 5.6
5 5.77
我尝试使用 for 循环将值拉入一个新的数据帧,然后使用“statistics.stdev”,但我似乎无法让它工作。任何帮助真的很感激!
更新!
pd.concat([d.set_index('Speed').values for d in df_power], axis=1).std(1)
这行得通。虽然,我忘了提到速度的值在数据帧之间并不总是相同的。一些数据框会丢失一些数据框,最终会在这些情况下返回 nan 。
解决方案
您可以concat
使用std
:
list_df = [df1, df2, df3, ...]
pd.concat([d.set_index('Speed') for d in list_dfs], axis=1).std(1)
推荐阅读
- javascript - 错误:图像未显示在 CactusList 页面中
- elasticsearch - 如何在 Elastic Search 中添加主节点角色
- python - 删除 csv 文件中的重复值
- r - 将矩阵绘制为 cimg 对象时如何关闭平滑/模糊
- javascript - 如何在javascript中将值从一个范围映射到另一个范围?
- javascript - 如何从不同的文件导出/导入 Google Chrome 扩展程序中的变量 - Javascript
- c++ - 按属性搜索一组无序的对象并返回对应的对象
- javascript - Nodejs异步设置功能
- webrtc - 从 YUV420 ByteBuffer 创建 org.webrtc.JavaI420Buffer
- java - spring boot:登录后调用时出现 404