In my code, I'm assigning an idex to the date field, then converting it from string to datetime as below:
path = "/content/drive/MyDrive/ColabNotebooks/dataset/"
data = pd.read_csv(path+'2022Sales.csv', sep='\t', lineterminator='\r')
df = data.groupby(['DATE1']).agg({'QTY': "sum"})
df
Then I split the dataset into training and testing and plotting the data, as below:
train = df.loc[df.index < '2022-05-01']
test = df.loc[df.index >= '2022-05-01']
fig, ax = plt.subplots(figsize=(15, 5))
train.plot(ax=ax, label='Training Set', title='Data Train/Test Split')
test.plot(ax=ax, label='Test Set')
ax.axvline('2022-05-01', color='black', ls='--')
ax.legend(['Training Set', 'Test Set'])
plt.show()
Everything is fine, and I, getting the required outputs:
Now, I'm trying to do the same with multiple indexes, so I read the data as below:
path = "/content/drive/MyDrive/ColabNotebooks/dataset/"
data = pd.read_csv(path+'2022Sales.csv', sep='\t', lineterminator='\r')
df = data.groupby(['DATE1', 'ITEM_ID', 'SLS_CNTR_ID']).agg({'QTY': "sum"})
df
And I got the required dataframe correctly:

But now I've 2 issues:
- How can I convert index[0], i.e. the
'DATE1'field from str to date? - How can I compare the value of index[0], i.e. the
'DATE1'to the required periods, so I can plot the chart smoothly as I did before
