This thread didn't solved my problem.
This is my data:
Date Server
2019-02-13 A
2019-02-13 B
2019-02-13 B
2019-02-17 A
2019-02-17 B
2019-02-17 C
2019-02-19 C
2019-02-19 D
I need to get a list of the servers for a respective date range. I tried this code:
df['Date'] = pd.to_datetime(df['Date'], format='%Y%m%d').apply(lambda x: x.strftime(format='%Y-%m-%d'))
df = df.set_index(df['Date'])
### This formatting changes the cell content from a format like 20190217 to the
one represented above. Maybe there is already an error right here.###
start_date = pd.to_datetime('20190212', format='%Y%m%d').strftime(format='%Y-%m-%d')
end_date = pd.to_datetime('20190217', format='%Y%m%d').strftime(format='%Y-%m-%d')
The print statements however deliver the correct result, if I write the dates explicitly. However in my program I need to pipe in the dates by start_date and end_date.
print(df[df.Date.between('2019-02-12','2019-02-17')].Server.unique())
print(df.loc['2019-02-12':'2019-02-17'].Server.unique())
print(df.loc[start_date : end_date].Server.unique())
Output:
['A' 'B' 'C'] - correct
['A' 'B' 'C'] - correct
['A' 'B' 'C' 'D'] - incorrect
Which changes to my code do I need to apply?