I have a time series every which looks like this :




Time
Volume every minute




2023-05-25T00:00:00Z
284


2023-05-25T00:01:00Z
421


.
.


.
.


2023-05-27T23:58:00Z
894


2023-05-27T23:59:00Z
357




I have to make new CSV by iterating Time column finding unique date and making new columns with corresponding values of volume every minute. For example desired output:




Date
min1
min2
...
min1440




2023-05-25
284
421
...
578


2023-05-26
512
645
...
114


2023-05-27
894
357
...
765




i am able to fetch unique dates but after that i am clueless. please find my sample codes:
import pandas as pd

train_data = pd.read_csv('date25to30.csv')

print(pd.to_datetime(train_data['time']).dt.date.unique())


Find unique date from existing dataframe and make a new CSV with corresponding column values
First add parameter parse_dates to read_csv for convert Time column to datetimes:
train_data = pd.read_csv('date25to30.csv', parse_dates=['Time'])

Then create minutes by converting HH:MM:SS to timedeltas by to_timedelta and Series.dt.total_seconds, divide 60 and add 1 because python count from 0:
minutes = (pd.to_timedelta(train_data['Time'].dt.strftime('%H:%M:%S'))
             .dt.total_seconds()
             .div(60)
             .astype(int)
             .add(1))

Last pass to DataFrame.pivot_table with DataFrame.add_prefix:
df = (train_data.pivot_table(index=train_data['Time'].dt.date,
                             columns=minutes,
                             values='Volume',
                             aggfunc='sum').add_prefix('min'))
print (df)
Time         min1   min2  min1439  min1440
Time                                      
2023-05-25  284.0  421.0      NaN      NaN
2023-05-27    NaN    NaN    894.0    357.0

