May-09-2020, 09:34 AM
How do I make this for loop print the results as respective rows of the same dataframe. I tried this code but it doesn't seem to be working.
list2=[(('ATM',), ('ROA',)), (('ATM',), ('ROE',)), (('ATM',), ('NIM',)), (('ATM',), ('ROA', 'ROE'))] tm_final = {0: 3, 1: 6, 2: 4, 3: 2, 4: 0} totalrows=sum(tm_final[i]>0 for i in tm_final) df=pd.DataFrame(columns=['A','B','C']) for i in tm_final: if tm_final[i]>0: for j in range(totalrows): df.iloc[j,0]=i df.iloc[j,1]=str(list2[i]) df.iloc[j,2]=tm_final[i] print(df)