У меня есть большой текстовый файл сделок с данными, где я хочу фильтровать данные, когда я читаю их в кадр данных panda.
Я не могу заставить его фильтровать / получать данные, когда строка является датой.
2017-07-28 09:39:04.442 Allocation: BUY 7.0 AZN @ 43.665,
2017-07-28 09:39:07.724 Allocation: BUY 400.0 BT.A @ 3.022,
2017-07-28 09:39:08.802 Allocation: BUY 604.0 PFC @ 4.442,
2017-07-28 09:39:03.000 Allocation: SELL 1083 PFC @ 4.4432,
2017-07-28 09:39:03.000 Allocation: SELL 2350 PCT @ 10.3807,
2017-07-28 09:39:06.000 Allocation: SELL 2000 PFC @ 4.4565,
2017-07-28 09:39:07.000 Allocation: BUY 3000 VOD @ 2.21219,
2017-07-28 09:39:08.000 Allocation: SELL 2518 CLLN @ 0.5927,
Мой код ниже: он работает, когда фильтр похож на «BP», но не когда это «2017-07-28».
# this is to load the text file into content
with open(file) as f:
content = f.readlines()
content = [x.strip() for x in content]
# this is to filter the lines in the data
events = []
for line in content:
#if (line.find('Action') >0 and line.find('BP') > 0) :
if line.find('2017-07-28') > 0:
events.append(line.split(' '))
data = pd.DataFrame(events)