I want to append exactly one corresponding row from df_eng at the end of df12. df_eng & df12 have similar column size. I tried appending by df index (see my try in bold below), because len(Project_List) = len(df_eng). It can also be done by ‘Project’ row match I presume, but not sure how.
df_eng
Project Discipline
0 X1 AAA
1 X2 AAA
2 X3 AAA
3 X3 BBB
4 X3 CCC
…
df12
Project Discipline
0 X1 ZZZ
1 X2 ZZZ
2 X3 ZZZ
3 X4 ZZZ
4 X5 ZZZ
…
def X()
...
a_pivot = pd.pivot_table(data_a,index=['Discipline'],values=['Hours'],aggfunc=np.sum)
b_pivot = pd.pivot_table(data_b,index=['Discipline'],values=['Hours'],aggfunc=np.sum)
dfa = a_pivot.reset_index()
dfb = b_pivot.reset_index()
df12 = pd.merge(dfa, dfb, how='left', on='Discipline')
df12.insert(0, "Project", name, True)
df12['Hours_x'] = df12['Hours_x'].fillna(0)
df12['Hours_y'] = df12['Hours_y'].fillna(0)
df12['Hours_x'] = df12['Hours_x'] - df12['Hours_y']
**df12 = df12.append(df_eng.iloc[[i]], ignore_index=True)**
...
df12.plot()
pdf.savefig()
pdf.close()
...
for i in Project_List:
if i =='nan':
continue
try:
X(df_eng, data_a, data_b, name = i)
except:
print('This project encountered an error - ' + str(i))
Anyone keen enough to help out a coding rookie? Thanks!
ilegalnyj is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.