0
df=pd.DataFrame([
[56.7,7068.7], [57.19,7040.4], [60.71,8974.25], [60.875,8933.8],
[60.93,8891.3], [60.955,9479.7], [60.965,8962.35], [61.01,9044.8],
[61.01,8980.35], [61.145,9438.5], [61.28,9441.15], [61.375,9042.5],
[61.45,9374.5], [61.46,9431.6], [61.47,9533.5], [61.5,9427.8]
], columns=['RPM','Power'])
def round_to_value(number,roundto):
return (round(number/roundto) * roundto)
rpmstart=round_to_value(df['RPM'].min(),0.5)
rpmend=round_to_value(df['RPM'].max(),0.5)+1
groups=df.groupby(pd.cut(df['RPM'], np.arange(rpmstart,rpmend,1.0))).mean()
groups['band']=groups.index
df['avg']=pd.cut(df['RPM'], np.arange(rpmstart,rpmend,1.0))
原來的問題更換同一箱或類別的值是在這裏:Averaging a quantity for a particular RPM band and replacing in Pandas dataframe從一個數據幀到另一個
基本上,我希望能夠進行平均的功率爲1轉帶,從56.5-開始57.5在有效數據幀中,並替換數據幀'df'中相關RPM波段的功率值。 我做了這個代碼,它部分做到了,我被卡住了。 Dataframe'組'具有RPM範圍和平均功率,'df.avg'也具有RPM帶。我怎樣才能將'羣組'的力量替換成同一樂隊的'df'?你能幫我解決嗎?