LaVOZs

The World’s Largest Online Community for Developers

'; python - How to generate timeseries in one day per minutes? - LavOzs.Com

So I have dataframe:

import pandas as pd
from datetime import datetime

my_date = {'Date': ['2020-06-21 00:00:00'],
        'Dummy 1': [1000],
        'Dummy 2': [500]
        }

df = pd.DataFrame(my_date, columns = ['Date', 'Dummy 1', 'Dummy 2'])

Output:

Date                    Dummy 1 Dummy 2
2020-06-21 00:00:00     1000    500

I want to generate the date per minutes with the same data in 24 hours. Desired output:

    Date                    Dummy 1 Dummy 2
    2020-06-21 00:00:00     1000    500
    2020-06-21 00:01:00     1000    500
    2020-06-21 00:02:00     1000    500
    2020-06-21 00:03:00     1000    500
    2020-06-21 00:04:00     1000    500
    2020-06-21 00:05:00     1000    500
    ...
    2020-06-21 23:58:00     1000    500
    2020-06-21 23:59:00     1000    500

Generate dictionary by first row, set key Date by date_range and pass to DataFrame constructor:

d = df.iloc[0].to_dict()
d['Date'] = pd.date_range(df['Date'].iat[0], freq='Min', periods=60*24, name='Date')
df1 = pd.DataFrame(d)
print (df1)
                    Date  Dummy 1  Dummy 2
0    2020-06-21 00:00:00     1000      500
1    2020-06-21 00:01:00     1000      500
2    2020-06-21 00:02:00     1000      500
3    2020-06-21 00:03:00     1000      500
4    2020-06-21 00:04:00     1000      500
                 ...      ...      ...
1435 2020-06-21 23:55:00     1000      500
1436 2020-06-21 23:56:00     1000      500
1437 2020-06-21 23:57:00     1000      500
1438 2020-06-21 23:58:00     1000      500
1439 2020-06-21 23:59:00     1000      500

[1440 rows x 3 columns]

This will help you.

import pandas as pd

df = pd.DataFrame(
    {
        "Date": pd.date_range(
            start="2020-06-21", end="2020-06-22", freq="min", closed="left"
        )
    }
)
df["Dummy 1"] = 1000
df["Dummy 2"] = 500
print(df)

This is the result:

                    Date  Dummy 1  Dummy 2
0    2020-06-21 00:00:00     1000      500
1    2020-06-21 00:01:00     1000      500
2    2020-06-21 00:02:00     1000      500
3    2020-06-21 00:03:00     1000      500
4    2020-06-21 00:04:00     1000      500
...                  ...      ...      ...
1435 2020-06-21 23:55:00     1000      500
1436 2020-06-21 23:56:00     1000      500
1437 2020-06-21 23:57:00     1000      500
1438 2020-06-21 23:58:00     1000      500
1439 2020-06-21 23:59:00     1000      500
Related