簡體   English   中英

在 Pandas ZA7F5F35426B927411FC9231B56382

[英]Problem creating new Dataframe that depends on another Dataframe in Pandas Python

我正在嘗試基於此 Dataframe 創建一個新的 Dataframe 在此處輸入圖像描述

使用這段代碼,我正在嘗試創建一個新的 Dataframe 應該每秒給我一個新的行 X 次(這里 X = 1/15),所以在前 5 秒我應該得到 5/(1/15)= 'Risque' 列中相同的 75 行

 while i< 30:
    if (CC78.iloc[i]['Articulation']=="Cou"):
        if (CC78.iloc[i]['Duree'] < x):
            Cou2 = Cou2.append(pd.Series([CC78.iloc[i+j]['Risque']]), ignore_index=True)
            Frame2 = Frame2.append(pd.Series(i+j), ignore_index=True)   
        else: 
            res=(CC78.iloc[i]['Duree'] / x) + 1
            k=0
            while k <= int(res):                      
                Cou2 = Cou2.append(pd.Series([CC78.iloc[i+j]['Risque']]), ignore_index=True)
                Frame2 = Frame2.append(pd.Series(i+j), ignore_index=True)
                k=k+1
                j=j+1
    i=i+1

但我得到的結果是在此處輸入圖像描述

有時我有索引問題,例如:在此處輸入圖像描述

我真的不明白為什么生成的 Dataframe 與基礎 Dataframe 相同。 謝謝你的幫助。

編輯:我發現了問題,而不是 CC78.iloc[i+j],我應該使用 CC78.iloc[i],因為“i”與我的新 Dataframe 無關,它只用於基礎。

暫無
暫無

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

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