it's easy to multiply 2 columns, but some how my code returns NAN that i don't understand.
so i have these columns in df2 that have the same name also in df1. my goal was to multiply and then sum them together.
df1.columns=['ISIN', 'DSCD', 'GEOGN', 'SIC', 'GEOGC', 'COMMONSHARESOUTSTANDING',
'year', 'date', 'month', 'Mcap', 'TotalAssets', 'NItoCommon',
'NIbefEIPrefDiv', 'PrefDiv', 'NIbefPrefDiv', 'Sales',
'GainLossAssetSale', 'PPT', 'LTDebt', 'CommonEquity', 'PrefStock',
'OtherIncome', 'TotalLiabilities', 'PreTaxIncome', 'IncomeTaxes',
'OtherTA', 'OtherLiabilities', 'CashSTInv', 'OtherCA', 'OtherCL',
'TotalDiv', 'Country', 'Industry', 'IsSingleCountry', 'Mcap_w',
'NItoCommon_w', 'NIbefEIPrefDiv_w', 'PrefDiv_w', 'NIbefPrefDiv_w',
'Sales_w', 'GainLossAssetSale_w', 'PPT_w', 'LTDebt_w', 'CommonEquity_w',
'PrefStock_w', 'OtherIncome_w', 'TotalLiabilities_w', 'PreTaxIncome_w',
'IncomeTaxes_w', 'OtherTA_w', 'OtherLiabilities_w', 'CashSTInv_w',
'OtherCA_w', 'OtherCL_w', 'TotalDiv_w', 'fair_value', 'month__1',
'month__2', 'month__3', 'month__4', 'month__5', 'month__6', 'month__7',
'month__8', 'month__9', 'month__10', 'month__11', 'month__12',
'constant', 'V'
df2 has only one row while the other one is more than one row.
df2.columns = ['constant', 'TotalAssets', 'NItoCommon_w', 'NIbefEIPrefDiv_w',
'NIbefPrefDiv_w', 'Sales_w', 'GainLossAssetSale_w', 'PPT_w', 'LTDebt_w',
'CommonEquity_w', 'PrefStock_w', 'OtherIncome_w', 'TotalLiabilities_w',
'PreTaxIncome_w', 'IncomeTaxes_w', 'OtherTA_w', 'OtherLiabilities_w',
'CashSTInv_w', 'OtherCA_w', 'OtherCL_w', 'TotalDiv_w', 'month__1',
'month__2', 'month__3', 'month__4', 'month__5', 'month__6', 'month__7',
'month__8', 'month__9', 'month__10', 'month__11', 'month__12',
'Country', 'predicted_Mcap']
i need to multiply and sum these columns:
'TotalAssets', 'NItoCommon_w', 'NIbefEIPrefDiv_w',
'NIbefPrefDiv_w', 'Sales_w', 'GainLossAssetSale_w', 'PPT_w', 'LTDebt_w',
'CommonEquity_w', 'PrefStock_w', 'OtherIncome_w', 'TotalLiabilities_w',
'PreTaxIncome_w', 'IncomeTaxes_w', 'OtherTA_w', 'OtherLiabilities_w',
'CashSTInv_w', 'OtherCA_w', 'OtherCL_w', 'TotalDiv_w'
my code:
#adding a column to df1 to save the result in it.
df1['V']=0
for col in df2.iloc[:,1:20]:
df1['V']+=df1[col]*df2[col]
but the result is all NAN which is strange for me.