簡體   English   中英

如何使用一個數據幀中的值來計算大於或小於第二數據幀中的值的總數?

[英]How can the values from one dataframe be used to calculate the total number of values that are greater than or lesser than it in a second dataframe?

我有不同的數據框,分別為: step1step2step5 ,依此類推,它們每個都有一個名為BackGas_Flow_sccm的列。

我在每個數據幀的BackGas_Flow_sccm列上使用了.describe() ,以便使用25%和75%來創建新功能,例如IQRMaxMin 完成此操作后,我刪除了所有其他列,並將IQRMaxMin列保留在數據框中,結果如下:

                    Max                 Min
step1   0.0061032863849765275   0.0023474178403755843
step2   0.0061032863849765275   0.0023474178403755843
step5   0.43849765258215967     0.4309859154929577
step7   0.4394366197183098      0.43192488262910805
step12  0.44178403755868545     0.43051643192488265
step15  0.44413145539906096     0.4291079812206573
step16  0.44272300469483566     0.43145539906103286
step19  0.8201877934272299      0.5610328638497655
step24  0.008450704225352117    0.0009389671361502306
step25  0.0061032863849765275   0.0023474178403755843
step26  0.0061032863849765275   0.0023474178403755843
step27  0.0061032863849765275   0.0023474178403755843

現在,我想使用此數據框中的值,並在像step1step2step5類的數據框中計算大於Max或小於Min值的數量。

我可以做:

step1[step1['BacksGas_Flow_sccm'] > 0.0061032863849765275]
step1[step1['BacksGas_Flow_sccm'] < 0.0023474178403755843]

結果分別為424和135。 表示在step1 df中有424個值高於0.0061032863849765275,而有135個值低於0.0023474178403755843。 但是輸入數字0.0061032863849765275可能很乏味。

那么,有沒有一種方法可以更有效地實現呢?

編輯1 我的變量瀏覽器窗口中的數據框圖像

首先,您應該將這些dfs存儲到listdict

d={'step1':step1,'step2':step2....}

然后我們可以concat

s=pd.concat(d)['BacksGas_Flow_sccm'].unstack(0).describe().loc[['25%','75%']].T

之后,我們可以調用循環

for x in x.index:
    (d[x]['BacksGas_Flow_sccm'] > s.loc[x,'75%']).sum()
    (d[x]['BacksGas_Flow_sccm'] < s.loc[x,'25%']).sum()

或不帶for循環

pd.concat(d)['BacksGas_Flow_sccm'].gt(s['75%'],level=0).sum(level=0)

pd.concat(d)['BacksGas_Flow_sccm'].lt(s['25%'],level=0).sum(level=0)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM