The code I have works but it is very slow. I have a large dataframe based on days and a smaller dataframe that is the day data but averaged into weekly/monthly/yearly intervals. I am moving the change in direction "Turning Point" from the yearly (tempTimeScale) to the daily dataframe based on when the it changed on the day of that year rather than at the start/end of the year.
Is there a way to make it run faster?
import numpy as np
d = {"Turning Point Up": [10, np.nan, np.nan, 17, np.nan]}
dailyData = pd.DataFrame(data=d)
y = {"Turning Point Up": [17]}
tempTimeScale = pd.DataFrame(data=y)
tempTimeScale
def align(additive):
for indexD, rowD in dailyData.iterrows():
for indexY, rowY in tempTimeScale.iterrows():
if rowD["Turning Point Up"]==rowY["Turning Point Up"]:
dailyData.at[indexD,"Turning Point Up Y"]=rowY["Turning Point Up"]
o = {"Turning Point Up": [10, np.nan, np.nan, 17, np.nan], "Turning Point Up Y": [np.nan, np.nan, np.nan, 17, np.nan]}
exampleoutput = pd.DataFrame(data=o)
exampleoutput