Select the records

Report a typo

Let's assume there is a DataFrame, stored as df, which contains store records for May of 2022:

            items_sold  items_processing
date                                    
2022-05-01          14                 5
2022-05-02          18                 3
2022-05-03          10                 3
2022-05-04          18                 6
2022-05-05          14                 2

There is a date column in the YYYY-MM-DD pandas datetime format, but the index hasn't been set. Suppose there was a promotion from May 7th, 2022, up to May 12, 2022 (May 12th is included). Set the index to date and select all records that were made in the promotion period.

Print out the results of the selection.

Write a program in Python 3
import pandas as pd

df = pd.DataFrame({'date': pd.date_range(start='2022-05-01', end='2022-05-31'),
'items_sold': [14, 18, 10, 18, 14, 17, 10, 13, 10, 11, 12, 11, 16, 11, 16, 16, 16, 18, 12, 18, 12, 13, 13, 17, 19, 12, 16, 16, 16, 15, 11],
'items_processing': [5, 3, 3, 6, 2, 1, 5, 4, 6, 6, 2, 2, 5, 2, 6, 6, 4, 3, 6, 6, 1, 3, 1, 2, 3, 4, 2, 4, 3, 2, 1]})

#Your code here
___

Create a free account to access the full topic