'creating an exmpty dataframe with set row index and column index

I want to create an empty data frame with row index being each day and column index being time with 5min apart.So whenever I have to find a specific data dn time, I can use dataframe iloc feature to locate exact day and exact 5 min block of the day. for example please see below dataframe I am planing to create:

column index->  12:00:00  12:05:00  12:10:00 . . . . 24:00:00
row index   
2022/3/1
2022/3/2
2022/3/3
.
.
.
2022/3/31

I started by creating two date-range series:

df = pd.DataFrame()
d = pd.date_range(start='2022-03-01', end='2022-03-31')
t = pd.date_range(start='12:00:00', end='24:00:00')

Not sure how to proceed to complete 'd' as my row index and 't' as my column index.



Solution 1:[1]

The docstring of DataFrame indicates that you can specify the index and columns as you create it. So I would do that:

d = pd.date_range('2022-03-01', '2022-03-31', freq='D')
t = pd.date_range('12:00:00', '23:55:00', freq='5T').time  # Fix column index
df = pd.DataFrame(index=d, columns=t)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Corralien