Using Python 3.9 on mac with Pycharm. I have a .csv that contains two columns: dates/times as a string and a float:
time Value
0 2021-12-01 20:00:00 166
1 2021-12-01 19:59:00 165
The granularity of the time is by the minute, most days (some days are skipped). What I would like to do is take a single value for each listed day at a specific time, for instance every day contained in the data at 5pm. That way instead of having hundreds of values per day, I would have:
time Value
0 2021-12-02 17:00:00 166
1 2021-12-01 17:00:00 165
etc
The best I have come up with from reading about string/timeseries splitting is a for loop where the times are split and the index of 17:00:00 is used to form a new list
df = pd.read_csv('name')
datetime = df['time'].str.split()
temp_df = pd.DataFrame()
for _ in range(0, len(df)):
if datetime[_][1] == '17:00:00':
temp_df = temp_df.append(df.loc[[_]], ignore_index=True)
temp_df['time'] = pd.to_datetime(temp_df['time']) #make datetime for further computing
print(temp_df)
output:
...
time Value
175 2021-12-01 17:00:00 164
1083 2021-11-30 17:00:00 165
3313 2021-11-24 17:00:00 161
The other way would be to split it using df['Dates'] = pd.to_datetime(df['time']).dt.date, but it doesn't seem any less demanding than my current loop.
I've found sources on sorting/selecting dates/ranges (including the Pandas documentation), but none that allow you to maintain yet ignore the date while selecting for time?