Jovian
⭐️
Sign In
In [1]:
import numpy as np
import pandas as pd
In [13]:
from datetime import datetime
In [29]:
data = pd.read_csv('data.csv')
In [30]:
data.head()
Out[30]:
In [60]:
#function to convert string to date
def convert_date(x):
    return datetime.strptime(x, '%m/%d/%Y %H:%M')
In [62]:
type('2/20/2005 0:00')
Out[62]:
str
In [63]:
d = convert_date('2/20/2005 0:00')
In [64]:
type(d)
Out[64]:
datetime.datetime
In [54]:
#lambda expression to convert data from string to date.
data['ORDERDATE'] = data['ORDERDATE'].apply(lambda row: convert_date(row))
In [57]:
#getting order dates after a particular start date. 
start_date = datetime.strptime('2/20/2005 0:00', '%m/%d/%Y %H:%M')
data[data['ORDERDATE']>start_date]['ORDERDATE']
Out[57]:
23     2005-03-03
24     2005-04-08
25     2005-05-13
51     2005-03-09
52     2005-05-01
53     2005-05-31
77     2005-03-03
78     2005-04-07
79     2005-05-13
103    2005-03-03
104    2005-04-08
105    2005-05-13
129    2005-02-23
130    2005-03-17
131    2005-04-01
132    2005-05-06
158    2005-03-09
159    2005-05-01
160    2005-05-31
184    2005-03-03
185    2005-05-17
210    2005-03-17
211    2005-05-05
237    2005-03-09
238    2005-05-01
239    2005-05-31
263    2005-03-03
264    2005-04-08
265    2005-05-13
290    2005-05-05
          ...    
2611   2005-03-01
2612   2005-03-28
2613   2005-05-06
2639   2005-05-01
2640   2005-05-31
2662   2005-03-03
2663   2005-03-30
2664   2005-04-03
2665   2005-05-10
2687   2005-03-01
2688   2005-03-30
2689   2005-04-03
2690   2005-05-10
2714   2005-03-01
2715   2005-03-28
2716   2005-05-06
2740   2005-03-01
2741   2005-03-28
2742   2005-05-06
2766   2005-03-01
2767   2005-03-30
2768   2005-04-03
2769   2005-05-10
2793   2005-03-01
2794   2005-03-30
2795   2005-04-01
2796   2005-05-09
2820   2005-03-01
2821   2005-03-28
2822   2005-05-06
Name: ORDERDATE, Length: 301, dtype: datetime64[ns]
In [80]:
start_date = input("enter start date in mm/dd/yyyy format")
enter start date in mm/dd/yyyy format05/01/2005
In [81]:
start_date =  datetime.strptime(start_date, '%m/%d/%Y')
In [82]:
start_date
Out[82]:
datetime.datetime(2005, 5, 1, 0, 0)
In [83]:
end_date = input("enter start date in mm/dd/yyyy format")
enter start date in mm/dd/yyyy format05/30/2005
In [84]:
end_date =  datetime.strptime(end_date, '%m/%d/%Y')
In [85]:
end_date
Out[85]:
datetime.datetime(2005, 5, 30, 0, 0)
In [86]:
data[(data['ORDERDATE']>start_date) & (data['ORDERDATE']<end_date)]['ORDERNUMBER']
Out[86]:
25      10417
79      10417
105     10417
132     10414
185     10419
211     10413
265     10417
290     10413
315     10419
341     10413
366     10419
392     10412
419     10419
474     10419
551     10419
577     10416
599     10420
625     10419
652     10419
678     10412
701     10420
726     10412
752     10420
779     10412
803     10416
829     10417
855     10421
880     10419
960     10414
1012    10414
        ...  
1867    10420
1893    10419
1920    10415
1943    10420
1969    10414
1996    10419
2023    10416
2045    10420
2071    10412
2121    10416
2196    10416
2248    10412
2275    10413
2326    10416
2377    10416
2404    10412
2431    10413
2482    10414
2508    10416
2533    10414
2560    10415
2587    10416
2613    10414
2665    10416
2690    10416
2716    10414
2742    10414
2769    10416
2796    10415
2822    10414
Name: ORDERNUMBER, Length: 85, dtype: int64
In [ ]:
 
In [71]:
import jovian
In [ ]:
jovian.commit()
[jovian] Saving notebook..
In [ ]: