I need to select the data frame using my train period shown below but it ran into error always.
train_period = [
['1/1/2018', '10/30/2018']]
train_period = [[datetime.strptime(y,'%m/%d/%Y') for y in x] for x in train_period]
for tp in train_period:
print()
#print('Begin:%d End:%d' % (tp[0], tp[1]))
print()
df_train_period = df_sku[
(df_sku['To_Date'] >= tp[begin]) & (df_sku['To_Date'] <= tp[end])]
答案 0 :(得分:1)
Your 'To_Date'
column needs to be of dtype
np.datetime
in order to do datetime string filtering, so firstly convert first:
df_sku['To_Date'] = pd.to_datetime(df_sku, format='%m/%d/%Y')
then your code will work. You can always check the dtype
by calling df_sku['To_Date'].dtype