1
私は、時系列の各サブシリーズの特徴である時系列(列1)と値(列2)を持つデータフレームを持っています。 条件を満たすサブシリーズを削除するにはどうすればよいですか?条件を満たすサブシリーズ(データフレーム内の行)を削除します。
削除する行を示す機能を持つ追加の列を作成するためにループを作成しようとしましたが、このソリューションは非常に計算コストが高いです(列に10mlのレコードがあります)。コード(遅いソリューション):重複をnumpy.unique
でnumpy.concatenate
によってインデックスの配列を作成するための削除のために
import numpy as np
import pandas as pd
# sample data (smaller than actual df)
# length of df = 100; should be 10000000 in the actual data frame
time_ser = 100*[25]
max_num = 20
distance = np.random.uniform(0,max_num,100)
to_remove= 100*[np.nan]
data_dict = {'time_ser':time_ser,
'distance':distance,
'to_remove': to_remove
}
df = pd.DataFrame(data_dict)
subser_size = 3
maxdist = 18
# loop which creates an additional column which indicates which indexes should be removed.
# Takes first value in a subseries and checks if it meets the condition.
# If it does, all values in subseries (i.e. rows) should be removed ('wrong').
for i,d in zip(range(len(df)), df.distance):
if d >= maxdist:
df.to_remove.iloc[i:i+subser_size] = 'wrong'
else:
df.to_remove.iloc[i] ='good'
を受け入れていただき、ありがとうございます。あなたもupvoteすることができます - マークを受け入れる上記の '0 'の上の小さな三角形をクリックします。ありがとう。 – jezrael