I have a large dataframe df1
with many data columns, two of which are dates
and colNum
. I have built a second dataframe df2
which spans the date range and colNum
of df1
. I now want to fill df2
with a third column (any of the many other data columns) of df1
which meet the criteria of dates
and colNum
from df1
that match dateIndex
and colNum
of df2
.
I've tried various incarnations of MERGE
with no success.
I can loop through the combinations, but df1
is very large (270k, 2k) so it takes forever to do fill one df2
from one of df1
's columns, let alone all of them.
Slow looping version
dataList = ['revt']
for i in dataList:
goodRows = df1.index[~np.isnan(df1[i])].tolist()
for j in goodRows:
df2.loc[df1['dates'][j], str(df1['colNum'][j])] = df1[i][j]