I have the following dataframe
print(df.head(5))
date places_occupees
0 2017-01-01 00:00:00.0000000 238
1 2017-01-01 00:01:00.0000000 238
2 2017-01-01 00:02:00.0000000 238
3 2017-01-01 00:03:00.0000000 238
4 2017-01-01 00:04:00.0000000 238
5 2017-01-01 00:05:00.0000000 238
(please note that the date column type is string)
I have a list of strings that I will use to sort data in the dataframe.
print(list_holidays)
['2017-01-01', '2017-05-01', '2017-05-08', '2017-07-14', '2017-11-11', '2017-04-17', '2017-06-05', '2017-05-25', '2017-08-15', '2017-11-01', '2017-12-25']
then I create a new empty dataframe with the same 2 columns. I will fill it with data using the loop:
new_df = pd.DataFrame(columns=['date', 'places_occupees'])
Here is what I used but returns an empty dataframe
for i in list_holidays:
filter = df[df['date'].str.contains(i)]
new_df['date'].append(filter.date)
new_df['places_occupes'].append(filer.places_occupees)
What I would like to do is to fill the new_df 'date' column with the dates obtained after sorting and to fill the new_df 'places_occupees' column with the values obtained after sorting that should look like the initial dataframe but after applying a filter.
2017-07-01)