Home > OS >  How to REPLACE INTEGERS on the index row of a dataframe WITH TIME INTERVAL using pandas?
How to REPLACE INTEGERS on the index row of a dataframe WITH TIME INTERVAL using pandas?

Time:03-31

Here is the data frame and I want to change the integers 1-74 to time intervals starting from 5:00 to 24:00 with 15 minutes intervals. The integers will be mapped thus (1, 2, 3, 4, ..., 72, 73, 74) to (5:30, 5:45, 6:00, 6:15, ..., 23:30, 23:45, 24:00).screeshot of dataframe

I'm expecting a result like this. I have done it manually using excel functions. I need a way to do it with python fscreenshot from excelunctions.

CodePudding user response:

You can generate the time series and replace the column names.

from datetime import datetime as dt
from datetime import timedelta

data.columns = [(dt.strptime('5:30', '%H:%M')   i * timedelta(minutes=15)).strftime('%H:%M') for i in range(75)]

CodePudding user response:

You can use pd.date_range:

df.columns = pd.date_range('5:30', freq='15T', periods=len(df.columns)).strftime('%H:%M')
  • Related