大家好
我有以下数据框
depth sbl
6796.000 70
6810.001 70
6810.002 60
6856.001 60
我希望用户输入多少司的sbl,他希望因此 然后深度也随之增加
我无法找到一种方法让用户输入每个sbl有多少个分区。我只能定义所有sbl的声誉数量
这是我想要的一个例子
对于sbl 70(3个分区用户输入) 对于sbl 60(5个分区用户输入)
depth sbl
6796.000 70
6803.0005 70
6810.001 70
6810.002 60
6821.5 60
6833 60
6844.5 60
6856.001 60
df= pd.read_csv('sqbd.csv')
#state numbers of divisions ; user states the value here
N = 3
#seperating data by min and maxes (top& bottom)
df_mx= df.loc[df.groupby('sbl')['depth'].idxmax()]
df_mn= df.loc[df.groupby('sbl')['depth'].idxmin()]
#inteporlate between min and max with N as an increment "resample by N"
new_x = np.array([np.linspace(i, j, N) for i, j in zip(df_mn['depth'], df_mx['depth'])]).flatten()
new_y = df_mn['sbl'].loc[np.repeat(df_mn.index.values, N)]
#join resampled arrays ,sort by depth and reindex the data
final_df = pd.DataFrame({'depth': new_x, 'sbl': new_y})
final_df=final_df.sort_values('depth')
final_df = final_df.reset_index(drop=True)
目前没有回答
相关问题 更多 >
编程相关推荐