以下に以前教えていただいたプログラムを示します.
説明はこのURLの通りです.(https://teratail.com/questions/188617)
このとき,最後の結果が
5
6
7
10
11
12
と,いう順番に出力されていますが,これを,
5 10
6 11
7 12
と,いう順番で出力したいです.
どのようにプログラムを変えたらよいでしょうか.
python
1import pandas as pd 2import io 3 4data = """ 51,100,0.145 62,110,0.146 73,120,0.147 84,130,0.148 95,140,0.149 106,150,0.150 117,145,0.150 128,140,0.149 139,130,0.150 1410,120,0.151 1511,150,0.160 1612,140,0.159 1713,130,0.160 1814,120,0.161 19""" 20 21df = pd.read_csv(io.StringIO(data), header=None) 22 23target = ((df.iloc[:, 2] == 0.15) | (df.iloc[:, 2] == 0.16)) 24result = df[target | target.shift(1) | target.shift(2)] 25 26target_idx = [] 27count = 0 28for idx,row in df.iterrows(): 29 # 範囲外で、条件に合致しない場合はなにもしない 30 if (count == 0) and (row[2] != 0.15) and (row[2] != 0.16): 31 continue 32 # 範囲内の場合はリストに追加 33 elif count < 3: 34 target_idx.append(idx) 35 count = (count + 1) if (count < 3) else 0 36 37target = df.loc[target_idx] 38# 0 1 2 39#5 6 150 0.150 40#6 7 145 0.150 41#7 8 140 0.149 42#10 11 150 0.160 43#11 12 140 0.159 44#12 13 130 0.160
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/07/04 13:55
2019/07/04 18:15