[英]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 米的距离间隔计算max
、 min
和average
高度值。
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.