前提・実現したいこと
Pandasで複数行のデータから判断して特定カラムにデータをセットしています。
処理時間をもっと縮める方法はないでしょうか?
発生している問題・WARNING MESSAGE & 処理速度
C:\anaconda3\lib\site-packages\pandas\core\indexing.py:1765: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy isetter(loc, value)
該当のソースコード
Python
1%%time 2wdf = dft1 # 関数に変更時に使うためワーク変数を用意 3wptn = 0 4if wdf.iloc[0,3]=='B': #1 5 wptn = wptn + 512 6if wdf.iloc[1,3]=='B': 7 wptn = wptn + 256 8if wdf.iloc[2,3]=='B': 9 wptn = wptn + 128 10if wdf.iloc[3,3]=='B': 11 wptn = wptn + 64 12if wdf.iloc[4,3]=='B': 13 wptn = wptn + 32 14if wdf.iloc[5,3]=='B': 15 wptn = wptn + 16 16if wdf.iloc[6,3]=='B': 17 wptn = wptn + 8 18if wdf.iloc[7,3]=='B': 19 wptn = wptn + 4 20if wdf.iloc[8,3]=='B': #9 21 wptn = wptn + 2 22 23for i in range(9,len(wdf)-1): 24 if wdf.iloc[i,3]=='B': 25 wptn = wptn + 1 26 wdf.iloc[i+1, 4] = wptn 27 wptn = (wptn * 2) & 0b1111111111
試したこと
下図のようにFor分を使い カラム(kei1_color)の直前10行分データを、R=1,B=0と置き換えて 10進数に変換したものを カラム(prv_ptn_no)に順次セットしていく。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。