python - Fill 24 hours of data into five years of hourly dataframe -


i have dataframe of 5 years worth of hourly data.

import datetime dt startdate = dt.date(2008,1,1) enddate = dt.date(2015,8,1) dfindex = pd.date_range(start=startdate,end=enddate,freq='h') dfcolumns = ['c1','c2','c2'] df = pd.dataframe(index=dfindex,columns=dfcolumns) 

i have dataframe 24 hours.

dftemp = pd.dataframe(np.random.randint(60,100,(24,3)),index=pd.date_range(startdate,periods=24,freq='h'),columns='c1 c2 c3'.split()) 

i fill each day of first dataframe data second dataframe. instead of looping through each day .. there simple way of achieving this?

in python can repeat list using * operator, example

print([1,2,3]*2) [1, 2, 3, 1, 2, 3] 

so example, repeat sample data len(df)/24 times , set original dataframe using iloc, (i've had select iloc[:-1,:] since index contains 1 time point on last day):

df.iloc[:-1,:] = dftemp.values.tolist()*(int(len(df)/24)) df.head() out[198]:                       c1  c2  c2 2008-01-01 00:00:00  98  88  79 2008-01-01 01:00:00  79  72  72 2008-01-01 02:00:00  67  72  70 2008-01-01 03:00:00  61  85  73 2008-01-01 04:00:00  81  66  92 

Comments

Popular posts from this blog

c# - Binding a comma separated list to a List<int> in asp.net web api -

Delphi 7 and decode UTF-8 base64 -

html - Is there any way to exclude a single element from the style? (Bootstrap) -