I want to combine a dataframe with datetime.
Here is my attempt.
import pandas as pd
from pandas import DataFrame
import numpy as np
# create df
df = pd.DataFrame(np.random.uniform(low=10.00, high=32.5, size=(5,2)), columns=['reference', 'target'])
df.head()
reference target
0 13.559319 24.057471
1 13.101118 19.323373
2 17.295842 18.991576
3 18.123597 13.121553
4 16.328118 28.981584
Then, a timestamp.
import datetime
for a in range(5): # 2 is the number of record
a = (datetime.date(2010, 1, 15) + datetime.timedelta(a))
print(a)
2010-01-15
2010-01-16
2010-01-17
2010-01-18
2010-01-19
How to combine both and assign 'date' as the column name for datetime?
final_df=df.assign(date=[(datetime.date(2010, 1, 15) + datetime.timedelta(a)) for a in range(5)])??pd.date_rangeorpd.to_datetimeuseful