简体   繁体   English

如何从python中另一列(连续数据)的范围数据中提取一列的平均值,最大值和最小值

[英]How to extract mean, max and min values of one column from a range data of the other column (continuous data) in python

I have a dataframe with two columns Distance(m) and height(m) .我有一个包含两列Distance(m)height(m)的数据框。 I want to calculate the max , min and average height values from an interval of 0.04439 m of distance.我想从 0.04439 米的距离间隔计算maxminaverage高度值。

Distance is a continuous series from 0 to 0.81m each 0.00222m with a total of 403 values length .距离是从0 到 0.81m 每个 0.00222m的连续系列,共有 403 个值 length

The aim is to extract 18 values (max min average) of Height from 18 intervals each 0.0439m distance (the continuous distance series between 0 and 0.81m)目的是从每个 0.0439m 距离(0 到 0.81m 之间的连续距离系列)的 18 个间隔中提取 Height 的 18 个值(最大最小平均值)

Then, create a dataframe (2 columns) of each distance interval and its respectively max min and avg value of height然后,创建每个距离间隔的数据框(2 列)及其分别的最大最小值和高度平均值

this is an example:这是一个例子:

Interval distance     Height_max(m)     Height_min(m)     Height_average(m)

1                       0.35            0.15           0.25  

2                       0.55            0.22           0.35  

3                       0.25            0.10           0.15

I have only 2 columns in my dataframe:我的数据框中只有 2 列:

Distance(m) = [0, 0.0022, 0.0044, .... 0.81 ]
Height(m) = [ 0, 0.1, 0.5, 0.4, 0.9, .... 0.1]

Does anyone have any suggestions that can help me?有没有人有任何可以帮助我的建议?

Thanks!谢谢!

I believe you need cut for bining column by intervals and then aggregate by GroupBy.agg with list of aggregation functions:我相信您需要按间隔cut合并列,然后通过GroupBy.agg与聚合函数列表聚合:

d = pd.cut(df['Distance'], [0, 0.0022, 0.0044, .... 0.81 ])
h = pd.cut(df['Height'],  [0, 0.1, 0.5, 0.4, 0.9, .... 0.1])

df.groupby([d, h])['Height'].agg(['min','max','mean'])

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Python中找到一列的最大和最小值以及其他两列的差异 - Find Max & Min of one column and difference of two other columns in Python 如何找到范围内的最小值和最大值并将其填充到 Pandas 中的新列? - How to find min and max values in a range and populate it to a new column in Pandas? Python - Pandas 列中两个值之间的最大范围不是列的最大值和最小值 - Python - Pandas Max Range Betwen two Values in a column that is not a max and min of column 在另一列的值定义的范围内查找最大值/平均值 - Find max/mean in range defined by values from another column 从分类数据类型列中提取均值 - Extract mean from categorical data type column 如何根据列值对列中的数据进行分组并分析其最大值或最小值? - How to group data in a column based on a column value and analyze the max or min on that? 如何从另一列的范围内的列计算平均值 - How to calculate mean values from a column from a range of another column 从 python 中的字典中提取最大值和最小值 - extract max and min values from a dictionary in python 如何使用'group by'和'cut'方法在pandas数据框中使用连续分布按一系列列值分组? - how to group by a range of column values using continuous distribution in pandas data frame using 'group by' and 'cut' method? 从带有Python的HTML表中仅提取一列数据? - Extract just one column of data from HTML table w/ Python?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM