Issue
I have 2 dataframes with the same column name but different amount of rows
data=ones((100,2))
df1=pd.DataFrame(data=data, columns = ('a','b'))
df2=pd.DataFrame({'a':[5,6,7,8,9],'b':[6,6,6,6,6]})
What I want to do is, multiply df2 to df1 but the df2 to repeat every 5 rows to the df1
What I did is
df6=pd.DataFrame(columns=('a','b'))
for x in range(0,90,5):
df6=df6.append(df2*df1.iloc[x:x+5,:])
But it only works for the first 5 rows an then I only get NaN
Solution
After adding .values to your indexed dataframe your code works.
df6=df6.append(df2.multiply(df1.iloc[x:x+5,:].values))
Answered By - 在去中国
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.